/**
 @file sys_usw_dmps_db.c

 @author  Copyright (C) 2021 Centec Networks Inc.  All rights reserved.

 @date 2021-11-19

 @version v2.0

*/

/****************************************************************************
 *
* Header Files
*
****************************************************************************/
#include "sal.h"
#include "ctc_error.h"
#include "ctc_debug.h"
#include "ctc_warmboot.h"

#include "sys_usw_common.h"
#include "sys_usw_dmps_db.h"
#include "sys_usw_mac.h"

#include "sys_usw_wb_common.h"
#include "sys_usw_register.h"
#include "drv_api.h"
#include "sys_usw_register.h"

/****************************************************************************
 *
* Defines and Macros
*
*****************************************************************************/

#define SYS_DMPS_DB_LOCK(lchip) \
    if(p_usw_dmps_db_master[lchip]->mutex) sal_mutex_lock(p_usw_dmps_db_master[lchip]->mutex)

#define SYS_DMPS_DB_UNLOCK(lchip) \
    if(p_usw_dmps_db_master[lchip]->mutex) sal_mutex_unlock(p_usw_dmps_db_master[lchip]->mutex)


#define DMPS_DB_PORT(dport)         p_usw_dmps_db_master[lchip]->dmps_db->port_db[dport]
#define DMPS_DB_MAC(mac_id)         p_usw_dmps_db_master[lchip]->dmps_db->mac_db[mac_id]
#define DMPS_DB_PCS(pcs_id)         p_usw_dmps_db_master[lchip]->dmps_db->pcs_db[pcs_id]
#define DMPS_DB_CHAN(chan_id)       p_usw_dmps_db_master[lchip]->dmps_db->chan_db[chan_id]
#define DMPS_DB_CHAN_RX(chan_id)    p_usw_dmps_db_master[lchip]->dmps_db->chan_rx_db[chan_id]
#define DMPS_DB_PSD(psd)            p_usw_dmps_db_master[lchip]->dmps_db->psd_db[psd]
#define DMPS_DB_LSD(lsd)            p_usw_dmps_db_master[lchip]->dmps_db->lsd_db[lsd]


#define SYS_DMPS_GET_SIZE(src_type, src_type_size) \
do {\
    switch(src_type)\
    {\
        case DMPS_DB_TYPE_PORT:\
            src_type_size = sizeof(sys_dmps_port_db_t);\
            break;\
        case DMPS_DB_TYPE_MAC:\
            src_type_size = sizeof(sys_dmps_mac_db_t);\
            break;\
        case DMPS_DB_TYPE_PSD:\
            src_type_size = sizeof(sys_dmps_psd_db_t);\
            break;\
        case DMPS_DB_TYPE_LSD:\
            src_type_size = sizeof(sys_dmps_lsd_db_t);\
            break;\
        case DMPS_DB_TYPE_PCS:\
            src_type_size = sizeof(sys_dmps_pcs_db_t);\
            break;\
        case DMPS_DB_TYPE_CHAN:\
            src_type_size = sizeof(sys_dmps_chan_db_t);\
            break;\
        case DMPS_DB_TYPE_CHAN_RX:\
            src_type_size = sizeof(sys_dmps_chan_rx_db_t);\
            break;\
        default:\
            break;\
    }\
} while(0)


#define SYS_DMPS_GET_SRC_DB(src_type, src_db) \
do {\
    switch(src_type)\
    {\
        case DMPS_DB_TYPE_PORT:\
            src_db = p_usw_dmps_db_master[lchip]->dmps_db->port_db;\
            break;\
        case DMPS_DB_TYPE_MAC:\
            src_db = p_usw_dmps_db_master[lchip]->dmps_db->mac_db;\
            break;\
        case DMPS_DB_TYPE_PSD:\
            src_db = p_usw_dmps_db_master[lchip]->dmps_db->psd_db;\
            break;\
        case DMPS_DB_TYPE_LSD:\
            src_db = p_usw_dmps_db_master[lchip]->dmps_db->lsd_db;\
            break;\
        case DMPS_DB_TYPE_PCS:\
            src_db = p_usw_dmps_db_master[lchip]->dmps_db->pcs_db;\
            break;\
        case DMPS_DB_TYPE_CHAN:\
            src_db = p_usw_dmps_db_master[lchip]->dmps_db->chan_db;\
            break;\
        case DMPS_DB_TYPE_CHAN_RX:\
            src_db = p_usw_dmps_db_master[lchip]->dmps_db->chan_rx_db;\
            break;\
        default:\
            break;\
    }\
} while(0)

enum sys_dmps_db_opf_index_e
{
    SYS_DMPS_DB_OPF_INDEX_CHAN,
    SYS_DMPS_DB_OPF_INDEX_CHAN_RX,
    SYS_DMPS_DB_OPF_INDEX_PORT,
    SYS_DMPS_DB_OPF_MAX_INDEX
};

enum sys_dmps_db_misc_chan_type_e
{
    SYS_USW_DMPS_DB_MISC_CHAN_TYPE_DMA,
    SYS_USW_DMPS_DB_MISC_CHAN_TYPE_OAM,
    SYS_USW_DMPS_DB_MISC_CHAN_TYPE_LOOP,
};

struct sys_dmps_mapping_set_s
{
    ctc_slistnode_t head;

    uint16 dport;
    uint16 mac_id;
    uint16 psd;
    uint16 lsd;
    uint16 pcs_id;
    uint16 chan_id;
    uint16 chan_rx_id;
};
typedef struct sys_dmps_mapping_set_s sys_dmps_mapping_set_t;

struct sys_dmps_mapping_search_info_s
{
    uint8 search_num;
    uint8 type;
    uint16 search_list[DMPS_MAX_NUM_PER_MODULE];
};
typedef struct sys_dmps_mapping_search_info_s sys_dmps_mapping_search_info_t;

enum sys_dmps_mapping_module_status_e
{
    MAPPING_IS_INVALID,
    MAPPING_IS_USED
};
typedef enum sys_dmps_mapping_module_status_e sys_dmps_mapping_module_status_t;

struct dmps_mapping_db_public_info_s
{
    uint16 id;
    uint8 valid;
    uint8 node_num;
    sys_dmps_mapping_set_t* node[DMPS_MAX_NUM_PER_MODULE];
};
typedef struct dmps_mapping_db_public_info_s dmps_mapping_db_public_info_t;

enum sys_dmps_db_dump_dst_flag_e
{
    SYS_DMPS_DB_DUMP_SCREEN = 0,
    SYS_DMPS_DB_DUMP_FILE,
    SYS_DMPS_DB_DUMP_BUTT
};
typedef enum sys_dmps_db_dump_dst_flag_e sys_dmps_db_dump_dst_flag_t;

struct sys_dmps_port_db_s
{
    dmps_mapping_db_public_info_t map;

    uint8  port_idx;    /* [Arctic] Cpumac port idx */
    uint8  port_type;   /* refer to sys_dmps_lport_type_t */
    uint8  if_type;     /* refer to ctc_port_if_type_t */
    uint8  if_mode;     /*refer to ctc_chip_serdes_mode_t*/
    uint8  fec_type;    /*sys_port_fec_type_t*/
    uint8  an_fec;      /* refer to ctc_port_fec_type_t */
    uint8  is_rsv;      /* is reserve for network and cpumac port */
    uint8  an_mode;     /* refer to ctc_port_auto_neg_mode_t */

    uint8  mdio_map;
    uint8  phy_map;
    uint8  devno_map;

    sys_dmps_an_ability_t an_ability;   /* AN ability */

    uint32 an_en              :1;       /* AN  enable/disable */
    uint32 old_cl73_status    :2;
    uint32 link_intr_en       :1;
    uint32 link_status        :1;
    uint32 unidir_en          :1;
    uint32 rx_rst_hold        :1;
    uint32 is_ctle_running    :1;
    uint32 xpipe_en           :2;       /* sys_chan_dir_t, bit0:rx, bit1:tx */
    uint32 is_an_first        :1;
    uint32 link_fsm           :4;       /*sys_usw_dmps_link_fsm_t*/
    uint32 link_mode          :2;       /*sys_usw_dmps_link_mode_t*/
    uint32 rsv                :15;
};
typedef struct sys_dmps_port_db_s sys_dmps_port_db_t;

struct sys_dmps_chan_db_s
{
    dmps_mapping_db_public_info_t map;

    uint8  core_id;
    uint8  pp_id;
    uint8  dp_id;
    uint8  txqm_id;

    uint16 sub_chan_id;
    uint16 mac_client_id;

    uint32 speed_value; /* xxx Mb/s */

    uint8  speed_mode;   /* refer to sys_port_speed_t */
    uint8  is_rsv;       /* is reserve for network and cpumac channel */
    uint8  prio;         /* 1: the chan is otn chan */
    uint8  rsv;
};
typedef struct sys_dmps_chan_db_s sys_dmps_chan_db_t;

struct sys_dmps_chan_rx_db_s
{
    dmps_mapping_db_public_info_t map;

    uint8  core_id;
    uint8  pp_id;
    uint8  dp_id;
    uint8  txqm_id;

    uint16 sub_chan_id;
    uint16 mac_client_id;

    uint32 speed_value; /* xxx Mb/s */

    uint8  speed_mode;   /* refer to sys_port_speed_t */
    uint8  is_rsv;      /* is reserve for network and cpumac channel */
    uint8  prio;       /* 1: the chan is otn chan */
    uint8  rsv;
};
typedef struct sys_dmps_chan_rx_db_s sys_dmps_chan_rx_db_t;

struct sys_dmps_mac_db_s
{
    dmps_mapping_db_public_info_t map;

    uint8 mac_speed;
    uint8 mac_group_id;
    uint8 mac_idx;
    uint8 en;
};
typedef struct sys_dmps_mac_db_s sys_dmps_mac_db_t;

struct sys_dmps_psd_db_s
{
    dmps_mapping_db_public_info_t map;

    uint8 pll_sel;  /* 0: disable,1:plla. 2:pllb    for TM it means cmu_id+1, 0: disable, 1: plla(CMU0), 2: pllb(CMU1), 3: pllc(CMU2) */
    uint8 rate_div; /*0: full, 1:1/2, 2:1/4, 3:1/8*/
    uint8 bit_width;    /* bit width*/
    uint8 rx_polarity;  /*0:normal, 1:reverse*/

    uint32 support_speed;   /* bmp sys_datapath_serdes_speed_t */

    uint32 serdes_speed;    /*speed value*/

    uint8 tx_polarity;  /*0:normal, 1:reverse*/
    uint8 ocs;  /*serdes over clock: ctc_chip_serdes_ocs_mode_t*/
    uint8 physical_lane_id; /*real serdes idx in group*/
    uint8 is_dyn;
};
typedef struct sys_dmps_psd_db_s sys_dmps_psd_db_t;

struct sys_dmps_lsd_db_s
{
    dmps_mapping_db_public_info_t map;

    uint8 logical_lane_id;  /*logic serdes idx in group*/
    uint8 pcs_l_idx;    /*lane idx in a pcs port*/
    uint8 hss_id;
    uint8 rsv;
};
typedef struct sys_dmps_lsd_db_s sys_dmps_lsd_db_t;

struct sys_dmps_pcs_db_s
{
    dmps_mapping_db_public_info_t map;

    uint8 pcs_idx;
    uint8 rx_rst_en;
    uint8 rsv;
};
typedef struct sys_dmps_pcs_db_s sys_dmps_pcs_db_t;

struct sys_dmps_db_s
{
    sys_dmps_port_db_t    port_db[DMPS_MAX_PORT_NUM];
    sys_dmps_mac_db_t     mac_db[DMPS_MAX_MAC_NUM];
    sys_dmps_lsd_db_t     lsd_db[DMPS_MAX_SERDES_NUM];
    sys_dmps_psd_db_t     psd_db[DMPS_MAX_SERDES_NUM];
    sys_dmps_pcs_db_t     pcs_db[DMPS_MAX_PCS_NUM];
    sys_dmps_chan_db_t    chan_db[DMPS_MAX_CHAN_NUM];
    sys_dmps_chan_rx_db_t chan_rx_db[DMPS_MAX_CHAN_NUM];
};
typedef struct sys_dmps_db_s sys_dmps_db_t;

struct sys_dmps_db_master_s 
{
    sal_mutex_t* mutex; /*SYS_DMPS_DB_LOCK*/

    /*for arctic: 0-191 is network chan, 192 and 193 is cpumac chan*/
    sys_dmps_db_chan2lsd_map_t chan_2_logic_serdes[DMPS_MAX_CORE_NUM][DMPS_NW_CPU_NUM_PER_CORE];
    uint16                     ext_lport_map[DMPS_MAX_PORT_NUM];    /*AT [0~511]lport, value~dport*/
    sys_dmps_db_cpumac_map_t   cpumac_map[DMPS_MAX_NUM_CPUMAC_MAP];
    ctc_slist_t                map_node_list;

    sys_dmps_db_t*             dmps_db; /*for AT only*/

    uint32 mac_group_is_valid[DMPS_MAX_CORE_NUM];   /*for AT only*/
    uint16 cpumac_dport[DMPS_MAX_NUM_CPUMAC_MAP];        /*for AT only*/
    sys_dmps_db_msg_handle_t dmps_msg_handle;     /*for AT only*/
    

    uint32 opf_type_dmps_db : 2; /*index 0: channel resource, index 1: port resource, refer to sys_dmps_db_opf_index_e*/
    uint32 core_pll         : 16;
    uint32 bpe_full_mode    : 2; /*0-disable 1-enable*/
    uint32 serdes_scale     : 4; /* for AT scm ag only, sys_dmps_db_serdes_scale_t */
    uint32 xpipe_alloc      : 2;   /*0: new resource same as old resource, 1/2 cut new resource*/
    uint32 rsv              : 6;
};
typedef struct sys_dmps_db_master_s sys_dmps_db_master_t;


extern int32
sys_usw_mac_get_port_capability(uint8 lchip, uint16 lport, sys_datapath_lport_attr_t** p_port);
extern int32
_sys_usw_dmps_db_dump_error_check(uint8 lchip, uint8 db_type, uint16 item_id, dmps_mapping_db_public_info_t* p_map, sal_file_t fp);

/****************************************************************************
 *
* Global and Declaration
*
*****************************************************************************/

sys_dmps_db_master_t* p_usw_dmps_db_master[CTC_MAX_LOCAL_CHIP_NUM_PP] = {NULL};
/****************************************************************************
 *
* Function
*
*****************************************************************************/


#define CTC_ERROR_RETURN_DB_UNLOCK(op) \
    { \
        int32 rv = (op); \
        if (rv < 0) \
        { \
            SYS_DMPS_DB_UNLOCK(lchip);\
            return (rv); \
        } \
    }



int32
_sys_usw_dmps_db_get_bpe_full_mode(uint8 lchip, uint8* p_bpe_full)
{
    CTC_PTR_VALID_CHECK(p_bpe_full);
    *p_bpe_full = (uint8) p_usw_dmps_db_master[lchip]->bpe_full_mode;

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_lport_2_dport(uint8 lchip, uint16 lport, uint16* p_dport)
{
    uint8  bpe_full_mode = 0;
    uint16 dport         = 0;

    SYS_CONDITION_RETURN(lport >= DMPS_MAX_PORT_NUM, CTC_E_INVALID_PARAM);
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_bpe_full_mode(lchip, &bpe_full_mode));
    if(bpe_full_mode)
    {
        dport = p_usw_dmps_db_master[lchip]->ext_lport_map[lport];
        dport = (DMPS_INVALID_VALUE_U16 == dport) ? lport : dport;
    }
    else
    {
        dport = lport;
    }
    SYS_USW_VALID_PTR_WRITE(p_dport, dport);

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_dport_2_lport(uint8 lchip, uint16 dport, uint16* p_lport)
{
    uint8  find_flag     = FALSE;
    uint8  bpe_full_mode = 0;
    uint16 tmp_lport     = 0;
    uint16 lport         = 0;

    SYS_CONDITION_RETURN(dport >= DMPS_MAX_PORT_NUM, CTC_E_INVALID_PARAM);
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_bpe_full_mode(lchip, &bpe_full_mode));
    if(bpe_full_mode)
    {
        for(tmp_lport = 0; tmp_lport < MCHIP_CAP(SYS_CAP_PORT_NUM_PER_CHIP); tmp_lport++)
        {
            if(dport == p_usw_dmps_db_master[lchip]->ext_lport_map[tmp_lport])
            {
                find_flag = TRUE;
                break;
            }
        }
        lport = (find_flag) ? tmp_lport : dport;
    }
    else
    {
        lport = dport;
    }
    SYS_USW_VALID_PTR_WRITE(p_lport, lport);

    return CTC_E_NONE;
}

uint16
sys_usw_dmps_db_get_lport_by_dport(uint8 lchip, uint16 dport)
{
    uint16 lport = DMPS_INVALID_VALUE_U16;
    SYS_DMPS_DB_LOCK(lchip);
    (void) _sys_usw_dmps_db_dport_2_lport(lchip, dport, &lport);
    SYS_DMPS_DB_UNLOCK(lchip);

    return lport;
}

int32
_sys_usw_dmps_db_get_xpipe_alloc(uint8 lchip, uint8* xpipe_alloc)
{
    CTC_PTR_VALID_CHECK(xpipe_alloc);
    *xpipe_alloc = p_usw_dmps_db_master[lchip]->xpipe_alloc;

    return CTC_E_NONE;
}

uint16
sys_usw_dmps_db_get_dport_by_lport(uint8 lchip, uint16 lport)
{
    uint16 dport = DMPS_INVALID_VALUE_U16;
    SYS_DMPS_DB_LOCK(lchip);
    (void) _sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport);
    SYS_DMPS_DB_UNLOCK(lchip);

    return dport;
}

uint16
sys_usw_dmps_db_get_dport_by_lport_raw(uint8 lchip, uint16 lport)
{
    uint16 dport = DMPS_INVALID_VALUE_U16;
    SYS_CONDITION_RETURN(lport >= DMPS_MAX_PORT_NUM, DMPS_INVALID_VALUE_U16);

    SYS_DMPS_DB_LOCK(lchip);
    dport = p_usw_dmps_db_master[lchip]->ext_lport_map[lport];
    SYS_DMPS_DB_UNLOCK(lchip);

    return dport;
}

STATIC int32
_sys_usw_dmps_db_init_public_info(uint8 lchip, uint16 id, dmps_mapping_db_public_info_t* map)
{
    uint8 cnt = 0;

    map->id       = id;
    map->valid    = MAPPING_IS_INVALID;
    map->node_num = 0;
    for (cnt = 0; cnt < DMPS_MAX_NUM_PER_MODULE; cnt++)
    {
        map->node[cnt] = NULL;
    }

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_init_port(uint8 lchip, uint16 dport)
{
    sal_memset(&(DMPS_DB_PORT(dport)), 0xff, sizeof(sys_dmps_port_db_t));

    DMPS_DB_PORT(dport).is_rsv          = FALSE;
    DMPS_DB_PORT(dport).an_en           = FALSE;
    DMPS_DB_PORT(dport).unidir_en       = FALSE;
    DMPS_DB_PORT(dport).old_cl73_status = FALSE;
    DMPS_DB_PORT(dport).link_intr_en    = TRUE;
    DMPS_DB_PORT(dport).link_status     = FALSE;
    DMPS_DB_PORT(dport).rx_rst_hold     = FALSE;
    DMPS_DB_PORT(dport).is_ctle_running = TRUE;
    DMPS_DB_PORT(dport).xpipe_en        = 0;
    DMPS_DB_PORT(dport).an_fec          = (1 << CTC_PORT_FEC_TYPE_RS) | (1 << CTC_PORT_FEC_TYPE_BASER);
    DMPS_DB_PORT(dport).port_type       = SYS_DMPS_MAX_PORT_TYPE;
    DMPS_DB_PORT(dport).if_type         = CTC_PORT_IF_NONE;
    DMPS_DB_PORT(dport).if_mode         = CTC_CHIP_MAX_SERDES_MODE;
    DMPS_DB_PORT(dport).fec_type        = SYS_DMPS_FEC_TYPE_NONE;
    DMPS_DB_PORT(dport).an_mode         = CTC_PORT_AUTO_NEG_MODE_NONE;
    DMPS_DB_PORT(dport).an_ability.base_ability0 = 0;
    DMPS_DB_PORT(dport).an_ability.base_ability1 = 0;
    DMPS_DB_PORT(dport).an_ability.np0_ability0  = 0;
    DMPS_DB_PORT(dport).an_ability.np0_ability1  = 0;
    DMPS_DB_PORT(dport).an_ability.np1_ability0  = 0;
    DMPS_DB_PORT(dport).an_ability.np1_ability1  = 0;
    DMPS_DB_PORT(dport).mdio_map  = DMPS_INVALID_VALUE_U8;
    DMPS_DB_PORT(dport).phy_map   = DMPS_INVALID_VALUE_U8;
    DMPS_DB_PORT(dport).devno_map = DMPS_INVALID_VALUE_U8;
    CTC_ERROR_RETURN(_sys_usw_dmps_db_init_public_info(lchip, dport, &(DMPS_DB_PORT(dport).map)));

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_init_chan(uint8 lchip, uint16 chan_id)
{
    sal_memset(&(DMPS_DB_CHAN(chan_id)), 0xff, sizeof(sys_dmps_chan_db_t));

    DMPS_DB_CHAN(chan_id).is_rsv        = FALSE;
    DMPS_DB_CHAN(chan_id).core_id       = DMPS_INVALID_VALUE_U8;
    DMPS_DB_CHAN(chan_id).pp_id         = DMPS_INVALID_VALUE_U8;
    DMPS_DB_CHAN(chan_id).dp_id         = DMPS_INVALID_VALUE_U8;
    DMPS_DB_CHAN(chan_id).txqm_id       = DMPS_INVALID_VALUE_U8;
    DMPS_DB_CHAN(chan_id).sub_chan_id   = DMPS_INVALID_VALUE_U16;
    DMPS_DB_CHAN(chan_id).mac_client_id = DMPS_INVALID_VALUE_U16;
    DMPS_DB_CHAN(chan_id).speed_mode    = SYS_PORT_SPEED_MAX;
    DMPS_DB_CHAN(chan_id).prio          = 0;
    DMPS_DB_CHAN(chan_id).speed_value   = 0;
    CTC_ERROR_RETURN(_sys_usw_dmps_db_init_public_info(lchip, chan_id, &(DMPS_DB_CHAN(chan_id).map)));

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_init_chan_rx(uint8 lchip, uint16 chan_id)
{
    sal_memset(&(DMPS_DB_CHAN_RX(chan_id)), 0xff, sizeof(sys_dmps_chan_rx_db_t));

    DMPS_DB_CHAN_RX(chan_id).is_rsv        = FALSE;
    DMPS_DB_CHAN_RX(chan_id).core_id       = DMPS_INVALID_VALUE_U8;
    DMPS_DB_CHAN_RX(chan_id).pp_id         = DMPS_INVALID_VALUE_U8;
    DMPS_DB_CHAN_RX(chan_id).dp_id         = DMPS_INVALID_VALUE_U8;
    DMPS_DB_CHAN_RX(chan_id).txqm_id       = DMPS_INVALID_VALUE_U8;
    DMPS_DB_CHAN_RX(chan_id).sub_chan_id   = DMPS_INVALID_VALUE_U16;
    DMPS_DB_CHAN_RX(chan_id).mac_client_id = DMPS_INVALID_VALUE_U16;
    DMPS_DB_CHAN_RX(chan_id).speed_mode    = SYS_PORT_SPEED_MAX;
    DMPS_DB_CHAN_RX(chan_id).prio          = 0;
    DMPS_DB_CHAN_RX(chan_id).speed_value   = 0;
    CTC_ERROR_RETURN(_sys_usw_dmps_db_init_public_info(lchip, chan_id, &(DMPS_DB_CHAN_RX(chan_id).map)));

    return CTC_E_NONE;
}


STATIC int32
_sys_usw_dmps_db_init_mac(uint8 lchip, uint16 mac_id)
{
    sal_memset(&(DMPS_DB_MAC(mac_id)), 0xff, sizeof(sys_dmps_mac_db_t));

    DMPS_DB_MAC(mac_id).en = FALSE;
    CTC_ERROR_RETURN(_sys_usw_dmps_db_init_public_info(lchip, mac_id, &(DMPS_DB_MAC(mac_id).map)));

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_init_lsd(uint8 lchip, uint16 lsd)
{
    sal_memset(&(DMPS_DB_LSD(lsd)), 0xff, sizeof(sys_dmps_lsd_db_t));

    CTC_ERROR_RETURN(_sys_usw_dmps_db_init_public_info(lchip, lsd, &(DMPS_DB_LSD(lsd).map)));

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_init_psd(uint8 lchip, uint16 psd)
{
    sal_memset(&(DMPS_DB_PSD(psd)), 0xff, sizeof(sys_dmps_psd_db_t));

    DMPS_DB_PSD(psd).ocs           = CTC_CHIP_SERDES_OCS_MODE_NONE;
    DMPS_DB_PSD(psd).serdes_speed  = 0;
    DMPS_DB_PSD(psd).support_speed = 0;
    DMPS_DB_PSD(psd).is_dyn        = FALSE;
    CTC_ERROR_RETURN(_sys_usw_dmps_db_init_public_info(lchip, psd, &(DMPS_DB_PSD(psd).map)));

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_init_pcs(uint8 lchip, uint16 pcs_id)
{
    sal_memset(&(DMPS_DB_PCS(pcs_id)), 0xff, sizeof(sys_dmps_pcs_db_t));

    DMPS_DB_PCS(pcs_id).pcs_idx  = DMPS_INVALID_VALUE_U8;
    DMPS_DB_PCS(pcs_id).rx_rst_en= FALSE;
    CTC_ERROR_RETURN(_sys_usw_dmps_db_init_public_info(lchip, pcs_id, &(DMPS_DB_PCS(pcs_id).map)));

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_init(uint8 lchip)
{
    uint16 cnt = 0;

    for (cnt = 0; cnt < DMPS_MAX_PORT_NUM; cnt++)
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_init_port(lchip, cnt));
    }

    for (cnt = 0; cnt < DMPS_MAX_MAC_NUM; cnt++)
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_init_mac(lchip, cnt));
    }

    for (cnt = 0; cnt < DMPS_MAX_SERDES_NUM; cnt++)
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_init_lsd(lchip, cnt));
    }

    for (cnt = 0; cnt < DMPS_MAX_SERDES_NUM; cnt++)
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_init_psd(lchip, cnt));
    }

    for (cnt = 0; cnt < DMPS_MAX_PCS_NUM; cnt++)
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_init_pcs(lchip, cnt));
    }

    for (cnt = 0; cnt < DMPS_MAX_CHAN_NUM; cnt++)
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_init_chan(lchip, cnt));
    }

    for (cnt = 0; cnt < DMPS_MAX_CHAN_NUM; cnt++)
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_init_chan_rx(lchip, cnt));
    }

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_init_opf(uint8 lchip)
{
    sys_usw_opf_t       opf;
    uint8       opf_type_dmps_db = 0;

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    CTC_ERROR_RETURN(sys_usw_opf_init(lchip, &opf_type_dmps_db, SYS_DMPS_DB_OPF_MAX_INDEX, "opf-type-chan"));
    p_usw_dmps_db_master[lchip]->opf_type_dmps_db = opf_type_dmps_db;

    /*chan_tx resource*/
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_CHAN;
    opf.pool_type  = opf_type_dmps_db;
    CTC_ERROR_RETURN(sys_usw_opf_init_offset(lchip, &opf, 0, MCHIP_CAP(SYS_CAP_CHANNEL_NUM)));
    /*chan_rx resource*/
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_CHAN_RX;
    opf.pool_type  = opf_type_dmps_db;
    CTC_ERROR_RETURN(sys_usw_opf_init_offset(lchip, &opf, 0, MCHIP_CAP(SYS_CAP_CHANNEL_NUM)));
    /*port resource*/
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_PORT;
    opf.pool_type  = opf_type_dmps_db;
    CTC_ERROR_RETURN(sys_usw_opf_init_offset(lchip, &opf, 0, MCHIP_CAP(SYS_CAP_PORT_NUM)));

    return CTC_E_NONE;
}

/*if index is out of bound, or db not in use, return FALSE*/
STATIC uint8
_sys_usw_dmps_db_is_valid_id(uint8 lchip, uint8 db_type, uint16 db_id)
{
    uint8 valid_flag = TRUE;

    switch(db_type)
    {
        case DMPS_DB_TYPE_PSD:
            if((DMPS_MAX_SERDES_NUM <= db_id) || (MAPPING_IS_INVALID == DMPS_DB_PSD(db_id).map.valid))
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_LSD:
            if((DMPS_MAX_SERDES_NUM <= db_id) || (MAPPING_IS_INVALID == DMPS_DB_LSD(db_id).map.valid))
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_PCS:
            if((DMPS_MAX_PCS_NUM <= db_id) || (MAPPING_IS_INVALID == DMPS_DB_PCS(db_id).map.valid))
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_PORT:
            if((DMPS_MAX_PORT_NUM <= db_id) || (MAPPING_IS_INVALID == DMPS_DB_PORT(db_id).map.valid))
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_MAC:
            if((DMPS_MAX_MAC_NUM <= db_id) || (MAPPING_IS_INVALID == DMPS_DB_MAC(db_id).map.valid))
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_CHAN:
            if((DMPS_MAX_CHAN_NUM <= db_id) || (MAPPING_IS_INVALID == DMPS_DB_CHAN(db_id).map.valid))
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_CHAN_RX:
            if((DMPS_MAX_CHAN_NUM <= db_id) || (MAPPING_IS_INVALID == DMPS_DB_CHAN_RX(db_id).map.valid))
            {
                valid_flag = FALSE;
            }
            break;
        default:
            valid_flag = FALSE;
            break;
    }

    return valid_flag;
}

STATIC uint8
_sys_usw_dmps_db_is_usable_id(uint8 lchip, uint8 db_type, uint16 db_id)
{
    uint8 valid_flag = TRUE;

    switch(db_type)
    {
        case DMPS_DB_TYPE_PSD:
            if(DMPS_MAX_SERDES_NUM <= db_id)
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_LSD:
            if(DMPS_MAX_SERDES_NUM <= db_id)
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_PCS:
            if(DMPS_MAX_PCS_NUM <= db_id)
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_PORT:
            if(DMPS_MAX_PORT_NUM <= db_id)
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_MAC:
            if(DMPS_MAX_MAC_NUM <= db_id)
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_CHAN:
            if(DMPS_MAX_CHAN_NUM <= db_id)
            {
                valid_flag = FALSE;
            }
            break;
        case DMPS_DB_TYPE_CHAN_RX:
            if(DMPS_MAX_CHAN_NUM <= db_id)
            {
                valid_flag = FALSE;
            }
            break;
        default:
            valid_flag = FALSE;
            break;
    }

    return valid_flag;
}


STATIC int32
_sys_usw_dmps_db_remove_node(uint8 lchip, dmps_mapping_db_public_info_t* map, sys_dmps_mapping_set_t* map_node)
{
    uint8 cnt       = 0;
    uint8 node_num  = 0;
    uint8 find_flag = FALSE;

    if ((NULL == map) || (NULL == map_node))
    {
        return CTC_E_NONE;
    }

    node_num = map->node_num;

    for (cnt = 0; cnt < node_num; cnt++)
    {
        if (cnt >= DMPS_MAX_NUM_PER_MODULE)
        {
            return CTC_E_INVALID_PARAM;
        }

        if (find_flag)
        {
            map->node[cnt - 1] = map->node[cnt];
            map->node[cnt]     = NULL;
        }

        if ((!find_flag) && (map_node == map->node[cnt]))
        {
            map->node_num--;
            map->node[cnt] = NULL;
            find_flag = TRUE;
        }
    }

    if (0 == map->node_num)
    {
        map->valid = MAPPING_IS_INVALID;
    }

    return CTC_E_NONE;
}

STATIC uint32
_sys_usw_dmps_db_get_map_node_in_list(uint8 lchip, sys_dmps_mapping_set_t* node_info, sys_dmps_mapping_set_t** map_node_p)
{
    sys_dmps_mapping_set_t* p_map_node = NULL;
    ctc_slistnode_t* node              = NULL;

    if ((NULL == node_info) || (NULL == map_node_p))
    {
        return CTC_E_NONE;
    }

    CTC_SLIST_LOOP(&(p_usw_dmps_db_master[lchip]->map_node_list), node)
    {
        p_map_node = _ctc_container_of(node, sys_dmps_mapping_set_t, head);
        if ((p_map_node->psd == node_info->psd)
            && (p_map_node->lsd == node_info->lsd)
            && (p_map_node->dport == node_info->dport)
            && (p_map_node->mac_id == node_info->mac_id)
            && (p_map_node->pcs_id == node_info->pcs_id)
            && (p_map_node->chan_id == node_info->chan_id)
            && (p_map_node->chan_rx_id == node_info->chan_rx_id))
        {
            *map_node_p = p_map_node;
            return CTC_E_NONE;
        }
    }

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_mapping_delete(uint8 lchip, sys_dmps_mapping_set_t* map_node)
{
    ctc_slist_delete_node(&(p_usw_dmps_db_master[lchip]->map_node_list), &(map_node->head));

    sal_memset(map_node, 0, sizeof(sys_dmps_mapping_set_t));

    mem_free(map_node);

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_mapping_add(uint8 lchip, sys_dmps_mapping_set_t* map_node, ctc_slistnode_t** prev_p)
{
    if (NULL == map_node)
    {
        return CTC_E_INVALID_PARAM;
    }

    /* If prev_p is NULL, add map_node in tail */
    if (NULL == prev_p)
    {
        ctc_slist_add_tail(&(p_usw_dmps_db_master[lchip]->map_node_list), &(map_node->head));
        return CTC_E_NONE;
    }

    if (NULL == *prev_p)
    {
        p_usw_dmps_db_master[lchip]->map_node_list.tail = &(map_node->head);
    }

    map_node->head.next = *prev_p;
    *prev_p = &(map_node->head);

    p_usw_dmps_db_master[lchip]->map_node_list.count++;

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_mapping_delete_node(uint8 lchip, sys_dmps_mapping_set_t* map_node)
{
    if (NULL == map_node)
    {
        return CTC_E_NONE;
    }

    /* 1. delete connection with every modules */
    if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, map_node->dport))
    {
        _sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_PORT(map_node->dport).map), map_node);
    }

    if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, map_node->mac_id))
    {
        _sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_MAC(map_node->mac_id).map), map_node);
    }

    if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, map_node->psd))
    {
        _sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_PSD(map_node->psd).map), map_node);
    }

    if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, map_node->lsd))
    {
        _sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_LSD(map_node->lsd).map), map_node);
    }

    if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, map_node->pcs_id))
    {
        _sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_PCS(map_node->pcs_id).map), map_node);
    }

    if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, map_node->chan_id))
    {
        _sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_CHAN(map_node->chan_id).map), map_node);
    }

    if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, map_node->chan_rx_id))
    {
        _sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_CHAN_RX(map_node->chan_rx_id).map), map_node);
    }

    /* 2. delete map node */
    _sys_usw_dmps_db_mapping_delete(lchip, map_node);
    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_mapping_build_node(uint8 lchip, sys_dmps_mapping_set_t* map_node_info, ctc_slistnode_t** prev_p)
{
    sys_dmps_mapping_set_t* new_map_node = NULL;
    dmps_mapping_db_public_info_t* p_map = NULL;

    if (NULL == map_node_info)
    {
        return CTC_E_INVALID_CONFIG;
    }

    new_map_node = (sys_dmps_mapping_set_t*)mem_malloc(MEM_DMPS_MODULE, sizeof(sys_dmps_mapping_set_t));
    if (NULL == new_map_node)
    {
        return CTC_E_NO_MEMORY;
    }
    sal_memcpy(new_map_node, map_node_info, sizeof(sys_dmps_mapping_set_t));

    /* Add the map_node to map_node_lists in relevant modules */
    if (new_map_node->lsd < DMPS_MAX_SERDES_NUM)
    {
        p_map = &(DMPS_DB_LSD(new_map_node->lsd).map);
        SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
        p_map->node[p_map->node_num] = new_map_node;
        p_map->node_num++;
        p_map->valid = MAPPING_IS_USED;
    }

    if (new_map_node->psd < DMPS_MAX_SERDES_NUM)
    {
        p_map = &(DMPS_DB_PSD(new_map_node->psd).map);
        SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
        p_map->node[p_map->node_num] = new_map_node;
        p_map->node_num++;
        p_map->valid = MAPPING_IS_USED;
    }

    if (new_map_node->dport < DMPS_MAX_PORT_NUM)
    {
        p_map = &(DMPS_DB_PORT(new_map_node->dport).map);
        SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
        p_map->node[p_map->node_num] = new_map_node;
        p_map->node_num++;
        p_map->valid = MAPPING_IS_USED;
    }

    if (new_map_node->mac_id < DMPS_MAX_MAC_NUM)
    {
        p_map = &(DMPS_DB_MAC(new_map_node->mac_id).map);
        SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
        p_map->node[p_map->node_num] = new_map_node;
        p_map->node_num++;
        p_map->valid = MAPPING_IS_USED;
    }

    if (new_map_node->pcs_id < DMPS_MAX_PCS_NUM)
    {
        p_map = &(DMPS_DB_PCS(new_map_node->pcs_id).map);
        SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
        p_map->node[p_map->node_num] = new_map_node;
        p_map->node_num++;
        p_map->valid = MAPPING_IS_USED;
    }

    if (new_map_node->chan_id < DMPS_MAX_CHAN_NUM)
    {
        p_map = &(DMPS_DB_CHAN(new_map_node->chan_id).map);
        SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
        p_map->node[p_map->node_num] = new_map_node;
        p_map->node_num++;
        p_map->valid = MAPPING_IS_USED;
    }

    if (new_map_node->chan_rx_id < DMPS_MAX_CHAN_NUM)
    {
        p_map = &(DMPS_DB_CHAN_RX(new_map_node->chan_rx_id).map);
        SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
        p_map->node[p_map->node_num] = new_map_node;
        p_map->node_num++;
        p_map->valid = MAPPING_IS_USED;
    }

    CTC_ERROR_RETURN(_sys_usw_dmps_db_mapping_add(lchip, new_map_node, prev_p));
    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_mapping_update_node(uint8 lchip, sys_dmps_mapping_set_t* old_info, sys_dmps_mapping_set_t* new_info)
{
    dmps_mapping_db_public_info_t* p_map = NULL;
    sys_dmps_mapping_set_t*     map_node = NULL;

    if ((NULL == old_info) || (NULL == new_info))
    {
        return CTC_E_NONE;
    }

    /* get previous map_node in list */
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_map_node_in_list(lchip, old_info, &map_node));

    if((DMPS_INVALID_VALUE_U16 == old_info->dport) && (DMPS_INVALID_VALUE_U16 == old_info->chan_id) && 
       (DMPS_INVALID_VALUE_U16 == old_info->mac_id) && (DMPS_INVALID_VALUE_U16 == old_info->pcs_id) && 
       (DMPS_INVALID_VALUE_U16 == old_info->lsd) && (DMPS_INVALID_VALUE_U16 == old_info->psd) &&
       (DMPS_INVALID_VALUE_U16 == old_info->chan_rx_id))
       /* build map_node */
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_mapping_build_node(lchip, new_info, NULL));
    }
    else if ((DMPS_INVALID_VALUE_U16 == new_info->dport) && (DMPS_INVALID_VALUE_U16 == new_info->chan_id) && 
       (DMPS_INVALID_VALUE_U16 == new_info->mac_id) && (DMPS_INVALID_VALUE_U16 == new_info->pcs_id) && 
       (DMPS_INVALID_VALUE_U16 == new_info->lsd) && (DMPS_INVALID_VALUE_U16 == new_info->psd) &&
       (DMPS_INVALID_VALUE_U16 == new_info->chan_rx_id))
       /* delete map_node */
    {
        CTC_ERROR_RETURN(_sys_usw_dmps_db_mapping_delete_node(lchip, map_node));
    }
    else
    /* update map_node */
    {
        if (NULL == map_node)
        {
            return CTC_E_INVALID_CONFIG;
        }

        if (map_node->dport != new_info->dport)
        {
            if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, map_node->dport))
            {
                (void)_sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_PORT(map_node->dport).map), map_node);
            }
            map_node->dport = new_info->dport;
            if (new_info->dport < DMPS_MAX_PORT_NUM)
            {
                p_map = &(DMPS_DB_PORT(new_info->dport).map);
                SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
                p_map->node[p_map->node_num] = map_node;
                p_map->node_num++;
                p_map->valid = MAPPING_IS_USED;
            }
        }

        if (map_node->mac_id != new_info->mac_id)
        {
            if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, map_node->mac_id))
            {
                (void)_sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_MAC(map_node->mac_id).map), map_node);
            }
            map_node->mac_id = new_info->mac_id;
            if (new_info->mac_id < DMPS_MAX_MAC_NUM)
            {
                p_map = &(DMPS_DB_MAC(new_info->mac_id).map);
                SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
                p_map->node[p_map->node_num] = map_node;
                p_map->node_num++;
                p_map->valid = MAPPING_IS_USED;
            }
        }

        if (map_node->psd != new_info->psd)
        {
            if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, map_node->psd))
            {
                (void)_sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_PSD(map_node->psd).map), map_node);
            }
            map_node->psd = new_info->psd;
            if (new_info->psd < DMPS_MAX_SERDES_NUM)
            {
                p_map = &(DMPS_DB_PSD(new_info->psd).map);
                SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
                p_map->node[p_map->node_num] = map_node;
                p_map->node_num++;
                p_map->valid = MAPPING_IS_USED;
            }
        }

        if (map_node->lsd != new_info->lsd)
        {
            if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, map_node->lsd))
            {
                (void)_sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_LSD(map_node->lsd).map), map_node);
            }
            map_node->lsd = new_info->lsd;
            if (new_info->lsd < DMPS_MAX_SERDES_NUM)
            {
                p_map = &(DMPS_DB_LSD(new_info->lsd).map);
                SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
                p_map->node[p_map->node_num] = map_node;
                p_map->node_num++;
                p_map->valid = MAPPING_IS_USED;
            }
        }

        if (map_node->pcs_id != new_info->pcs_id)
        {
            if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, map_node->pcs_id))
            {
                (void)_sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_PCS(map_node->pcs_id).map), map_node);
            }
            map_node->pcs_id = new_info->pcs_id;
            if (new_info->pcs_id < DMPS_MAX_PCS_NUM)
            {
                p_map = &(DMPS_DB_PCS(new_info->pcs_id).map);
                SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
                p_map->node[p_map->node_num] = map_node;
                p_map->node_num++;
                p_map->valid = MAPPING_IS_USED;
            }
        }

        if (map_node->chan_id != new_info->chan_id)
        {
            if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, map_node->chan_id))
            {
                (void)_sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_CHAN(map_node->chan_id).map), map_node);
            }
            map_node->chan_id = new_info->chan_id;
            if (new_info->chan_id < DMPS_MAX_CHAN_NUM)
            {
                p_map = &(DMPS_DB_CHAN(new_info->chan_id).map);
                SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
                p_map->node[p_map->node_num] = map_node;
                p_map->node_num++;
                p_map->valid = MAPPING_IS_USED;
            }
        }

        if (map_node->chan_rx_id != new_info->chan_rx_id)
        {
            if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, map_node->chan_rx_id))
            {
                (void)_sys_usw_dmps_db_remove_node(lchip, &(DMPS_DB_CHAN_RX(map_node->chan_rx_id).map), map_node);
            }
            map_node->chan_rx_id = new_info->chan_rx_id;
            if (new_info->chan_rx_id < DMPS_MAX_CHAN_NUM)
            {
                p_map = &(DMPS_DB_CHAN_RX(new_info->chan_rx_id).map);
                SYS_CONDITION_RETURN(DMPS_MAX_NUM_PER_MODULE <= p_map->node_num, CTC_E_INVALID_PARAM);
                p_map->node[p_map->node_num] = map_node;
                p_map->node_num++;
                p_map->valid = MAPPING_IS_USED;
            }
        }
    }
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAP, 1);
    return CTC_E_NONE;
}

STATIC uint8
_sys_usw_dmps_db_is_id_exist(uint8 lchip, uint16 id, uint8 num, uint16* arr_dst_id)
{
    uint8 cnt = 0;

    for (cnt = 0; cnt < num; cnt++)
    {
        if (id == arr_dst_id[cnt])
        {
            return TRUE;
        }
    }

    return FALSE;
}

STATIC int32
_sys_usw_dmps_db_get_single_relative_id(uint8 lchip, uint8 src_db, uint16 src_id, uint8 dst_db, uint16* p_dst_id)
{
    uint16 idx     = 0;
    uint16 dst_id  = DMPS_INVALID_VALUE_U16;
    dmps_mapping_db_public_info_t* p_map = NULL;

    CTC_PTR_VALID_CHECK(p_dst_id);
    if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, src_db, src_id))
    {
        return CTC_E_INVALID_PARAM;
    }

    switch(src_db)
    {
        case DMPS_DB_TYPE_PSD:
            p_map = &(DMPS_DB_PSD(src_id).map);
            break;
        case DMPS_DB_TYPE_LSD:
            p_map = &(DMPS_DB_LSD(src_id).map);
            break;
        case DMPS_DB_TYPE_PCS:
            p_map = &(DMPS_DB_PCS(src_id).map);
            break;
        case DMPS_DB_TYPE_PORT:
            p_map = &(DMPS_DB_PORT(src_id).map);
            break;
        case DMPS_DB_TYPE_MAC:
            p_map = &(DMPS_DB_MAC(src_id).map);
            break;
        case DMPS_DB_TYPE_CHAN:
            p_map = &(DMPS_DB_CHAN(src_id).map);
            break;
        case DMPS_DB_TYPE_CHAN_RX:
            p_map = &(DMPS_DB_CHAN_RX(src_id).map);
            break;
        default:
            break;
    }

    for(idx = 0; idx < p_map->node_num; idx++)
    {
        SYS_CONDITION_CONTINUE(NULL == p_map->node[idx]);

        switch(dst_db)
        {
            case DMPS_DB_TYPE_PSD:
                dst_id = p_map->node[idx]->psd;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, dst_id));
                break;
            case DMPS_DB_TYPE_LSD:
                dst_id = p_map->node[idx]->lsd;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, dst_id));
                break;
            case DMPS_DB_TYPE_PCS:
                dst_id = p_map->node[idx]->pcs_id;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, dst_id));
                break;
            case DMPS_DB_TYPE_PORT:
                dst_id = p_map->node[idx]->dport;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dst_id));
                break;
            case DMPS_DB_TYPE_MAC:
                dst_id = p_map->node[idx]->mac_id;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, dst_id));
                break;
            case DMPS_DB_TYPE_CHAN:
                dst_id = p_map->node[idx]->chan_id;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, dst_id));
                break;
            case DMPS_DB_TYPE_CHAN_RX:
                dst_id = p_map->node[idx]->chan_rx_id;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, dst_id));
                break;
            default:
                return CTC_E_INVALID_PARAM;
        }

        *p_dst_id = dst_id;
        return CTC_E_NONE;
    }

    *p_dst_id = DMPS_INVALID_VALUE_U16;
    return CTC_E_NONE;
}


STATIC int32
_sys_usw_dmps_db_get_relative_id(uint8 lchip, uint8 src_db, uint16 src_id, uint8 dst_db, 
                                      uint8* p_dst_num, uint16* arr_dst_id)
{
    uint16 idx     = 0;
    uint8  dst_num = 0;
    uint16 dst_id  = DMPS_INVALID_VALUE_U16;
    dmps_mapping_db_public_info_t* p_map = NULL;

    if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, src_db, src_id))
    {
        return CTC_E_INVALID_PARAM;
    }

    switch(src_db)
    {
        case DMPS_DB_TYPE_PSD:
            p_map = &(DMPS_DB_PSD(src_id).map);
            break;
        case DMPS_DB_TYPE_LSD:
            p_map = &(DMPS_DB_LSD(src_id).map);
            break;
        case DMPS_DB_TYPE_PCS:
            p_map = &(DMPS_DB_PCS(src_id).map);
            break;
        case DMPS_DB_TYPE_PORT:
            p_map = &(DMPS_DB_PORT(src_id).map);
            break;
        case DMPS_DB_TYPE_MAC:
            p_map = &(DMPS_DB_MAC(src_id).map);
            break;
        case DMPS_DB_TYPE_CHAN:
            p_map = &(DMPS_DB_CHAN(src_id).map);
            break;
        case DMPS_DB_TYPE_CHAN_RX:
            p_map = &(DMPS_DB_CHAN_RX(src_id).map);
            break;
        default:
            break;
    }

    if((NULL == p_dst_num) || (NULL == arr_dst_id))
    {
        dst_num = (0 == p_map->node_num) ? 0 : 1;
    }
    else
    {
        *p_dst_num = 0;
        dst_num = p_map->node_num;
    }
    for(idx = 0; idx < dst_num; idx++)
    {
        SYS_CONDITION_CONTINUE(NULL == &(arr_dst_id[idx]));
        SYS_CONDITION_CONTINUE(NULL == p_map->node[idx]);

        switch(dst_db)
        {
            case DMPS_DB_TYPE_PSD:
                dst_id = p_map->node[idx]->psd;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, dst_id));
                break;
            case DMPS_DB_TYPE_LSD:
                dst_id = p_map->node[idx]->lsd;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, dst_id));
                break;
            case DMPS_DB_TYPE_PCS:
                dst_id = p_map->node[idx]->pcs_id;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, dst_id));
                break;
            case DMPS_DB_TYPE_PORT:
                dst_id = p_map->node[idx]->dport;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dst_id));
                break;
            case DMPS_DB_TYPE_MAC:
                dst_id = p_map->node[idx]->mac_id;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, dst_id));
                break;
            case DMPS_DB_TYPE_CHAN:
                dst_id = p_map->node[idx]->chan_id;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, dst_id));
                break;
            case DMPS_DB_TYPE_CHAN_RX:
                dst_id = p_map->node[idx]->chan_rx_id;
                SYS_CONDITION_CONTINUE(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, dst_id));
                break;
            default:
                return CTC_E_INVALID_PARAM;
        }

        if (NULL == p_dst_num)
        {
            *arr_dst_id = dst_id;
            return CTC_E_NONE;
        }

        if (!_sys_usw_dmps_db_is_id_exist(lchip, dst_id, *p_dst_num, arr_dst_id))
        {
            arr_dst_id[*p_dst_num] = dst_id;
            (*p_dst_num)++;
        }
    }

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_get_dport_relative_id(uint8 lchip, uint16 dport, uint8 dst_db, uint16* p_dst_id)
{
    uint16 dst_id = DMPS_INVALID_VALUE_U16;
    dmps_mapping_db_public_info_t* p_map = NULL;

    if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport))
    {
        return CTC_E_INVALID_PARAM;
    }

    p_map = &(DMPS_DB_PORT(dport).map);

    if (NULL == p_map->node[0])
    {
        return CTC_E_INVALID_PARAM;
    }

    switch(dst_db)
    {
        case DMPS_DB_TYPE_PSD:
            dst_id = p_map->node[0]->psd;
            if(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, dst_id))
            {
                return CTC_E_INVALID_CONFIG;
            }
            break;
        case DMPS_DB_TYPE_LSD:
            dst_id = p_map->node[0]->lsd;
            if(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, dst_id))
            {
                return CTC_E_INVALID_CONFIG;
            }
            break;
        case DMPS_DB_TYPE_PCS:
            dst_id = p_map->node[0]->pcs_id;
            if(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, dst_id))
            {
                return CTC_E_INVALID_CONFIG;
            }
            break;
        case DMPS_DB_TYPE_PORT:
            dst_id = p_map->node[0]->dport;
            if(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dst_id))
            {
                return CTC_E_INVALID_CONFIG;
            }
            break;
        case DMPS_DB_TYPE_MAC:
            dst_id = p_map->node[0]->mac_id;
            if(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, dst_id))
            {
                return CTC_E_INVALID_CONFIG;
            }
            break;
        case DMPS_DB_TYPE_CHAN:
            dst_id = p_map->node[0]->chan_id;
            if(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, dst_id))
            {
                return CTC_E_INVALID_CONFIG;
            }
            break;
        case DMPS_DB_TYPE_CHAN_RX:
            dst_id = p_map->node[0]->chan_rx_id;
            if(!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, dst_id))
            {
                return CTC_E_INVALID_CONFIG;
            }
            break;
        default:
            return CTC_E_INVALID_PARAM;
    }

    SYS_USW_VALID_PTR_WRITE(p_dst_id, dst_id);

    return CTC_E_NONE;
}

STATIC int32 _sys_usw_dmps_db_set_internal_prop(uint8 lchip, uint8 db_prop, uint32 id, void* p_value)
{
    switch(db_prop)
    {
        case DMPS_DB_PORT_IDX:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).port_idx = *(uint8*)p_value;
            break;
        case DMPS_DB_PORT_TYPE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).port_type = *(uint8*)p_value;
            break;
        case DMPS_DB_PORT_IF_TYPE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).if_type = *(uint8*)p_value;
            break;
        case DMPS_DB_PORT_IF_MODE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).if_mode = *(uint8*)p_value;
            break;
        case DMPS_DB_PORT_FEC_TYPE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).fec_type = *(uint8*)p_value;
            break;
        case DMPS_DB_PORT_AN_FEC:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).an_fec = *(uint8*)p_value;
            break;
        case DMPS_DB_PORT_IS_RSV:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).is_rsv = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_XPIPE_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).xpipe_en = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_AN_MODE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).an_mode = *(uint32*)p_value;
            break;
        /*case DMPS_DB_PORT_AN_ABILITY:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            sal_memcpy(&(DMPS_DB_PORT(id).an_ability), p_value, sizeof(sys_dmps_an_ability_t));
            break;*/
        case DMPS_DB_PORT_AN_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).an_en = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_OLD_CL73_STAT:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).old_cl73_status = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_LINK_INTR_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).link_intr_en = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_LINK_STATUS:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).link_status = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_UNIDIR_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).unidir_en = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_RX_RST_HOLD:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).rx_rst_hold = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_IS_CTLE_RUN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).is_ctle_running = *(uint32*)p_value;
            break;
        case DMPS_DB_PORT_MDIO_MAP:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).mdio_map = *(uint8*)p_value;
            break;
        case DMPS_DB_PORT_PHY_MAP:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).phy_map = *(uint8*)p_value;
            break;
        case DMPS_DB_PORT_DEVNO_MAP:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PORT(id).devno_map = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_CORE_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).core_id = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_PP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).pp_id = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_DP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).dp_id = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_TXQM_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).txqm_id = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_SUB_CHAN_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).sub_chan_id = *(uint16*)p_value;
            break;
        case DMPS_DB_CHAN_MAC_CLIENT_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).mac_client_id = *(uint16*)p_value;
            break;
        case DMPS_DB_CHAN_SPEED_MODE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).speed_mode = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_IS_RSV:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).is_rsv = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_PRIO:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).prio = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_SPEED_VALUE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN(id).speed_value = *(uint32*)p_value;
            break;
        case DMPS_DB_CHAN_RX_CORE_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).core_id = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_RX_PP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).pp_id = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_RX_DP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).dp_id = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_RX_TXQM_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).txqm_id = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_RX_SUB_CHAN_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).sub_chan_id = *(uint16*)p_value;
            break;
        case DMPS_DB_CHAN_RX_MAC_CLIENT_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).mac_client_id = *(uint16*)p_value;
            break;
        case DMPS_DB_CHAN_RX_SPEED_MODE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).speed_mode = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_RX_IS_RSV:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).is_rsv = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_RX_PRIO:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).prio = *(uint8*)p_value;
            break;
        case DMPS_DB_CHAN_RX_SPEED_VALUE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_CHAN_RX(id).speed_value = *(uint32*)p_value;
            break;
        case DMPS_DB_MAC_SPEED:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_MAC(id).mac_speed = *(uint8*)p_value;
            break;
        case DMPS_DB_MAC_GROUP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_MAC(id).mac_group_id = *(uint8*)p_value;
            break;
        case DMPS_DB_MAC_IDX:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_MAC(id).mac_idx = *(uint8*)p_value;
            break;
        case DMPS_DB_MAC_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_MAC(id).en = *(uint8*)p_value;
            break;
        case DMPS_DB_PSD_PLL_SEL:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).pll_sel = *(uint8*)p_value;
            break;
        case DMPS_DB_PSD_RATE_DIV:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).rate_div = *(uint8*)p_value;
            break;
        case DMPS_DB_PSD_BIT_WIDTH:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).bit_width = *(uint8*)p_value;
            break;
        case DMPS_DB_PSD_RX_POLARITY:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).rx_polarity = *(uint8*)p_value;
            break;
        case DMPS_DB_PSD_SUPPORT_SPEED:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).support_speed = *(uint32*)p_value;
            break;
        case DMPS_DB_PSD_SPEED:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).serdes_speed = *(uint32*)p_value;
            break;
        case DMPS_DB_PSD_TX_POLARITY:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).tx_polarity = *(uint8*)p_value;
            break;
        case DMPS_DB_PSD_OCS:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).ocs = *(uint8*)p_value;
            break;
        case DMPS_DB_PSD_LANE_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).physical_lane_id = *(uint8*)p_value;
            break;
        case DMPS_DB_PSD_IS_DYN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PSD(id).is_dyn = *(uint8*)p_value;
            break;
        case DMPS_DB_LSD_LANE_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_LSD(id).logical_lane_id = *(uint8*)p_value;
            break;
        case DMPS_DB_LSD_PCSL_IDX:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_LSD(id).pcs_l_idx = *(uint8*)p_value;
            break;
        case DMPS_DB_LSD_HSS_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_LSD(id).hss_id = *(uint8*)p_value;
            break;
        case DMPS_DB_PCS_IDX:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PCS(id).pcs_idx = *(uint8*)p_value;
            break;
        case DMPS_DB_PCS_RX_RST_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            DMPS_DB_PCS(id).rx_rst_en = *(uint8*)p_value;
            break;
        default:
            return CTC_E_INVALID_PARAM;
    }
    return CTC_E_NONE;
}

STATIC int32 _sys_usw_dmps_db_get_internal_prop(uint8 lchip, uint8 db_prop, uint32 id, void* p_value)
{
    switch(db_prop)
    {
        /*case DMPS_DB_ADD_NODE:
        case DMPS_DB_DEL_NODE:
            ///TODO: tbd
            break;*/
        case DMPS_DB_PORT_IDX:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).port_idx;
            break;
        case DMPS_DB_PORT_TYPE:
            if(FALSE == _sys_usw_dmps_db_is_usable_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).port_type;
            break;
        case DMPS_DB_PORT_IF_TYPE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).if_type;
            break;
        case DMPS_DB_PORT_IF_MODE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).if_mode;
            break;
        case DMPS_DB_PORT_FEC_TYPE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).fec_type;
            break;
        case DMPS_DB_PORT_AN_FEC:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).an_fec;
            break;
        case DMPS_DB_PORT_IS_RSV:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).is_rsv;
            break;
        case DMPS_DB_PORT_AN_MODE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).an_mode;
            break;
        /*case DMPS_DB_PORT_AN_ABILITY:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            sal_memcpy(p_value, &(DMPS_DB_PORT(id).an_ability), sizeof(sys_dmps_an_ability_t));
            break;*/
        case DMPS_DB_PORT_AN_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PORT(id).an_en;
            break;
        case DMPS_DB_PORT_OLD_CL73_STAT:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PORT(id).old_cl73_status;
            break;
        case DMPS_DB_PORT_LINK_INTR_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PORT(id).link_intr_en;
            break;
        case DMPS_DB_PORT_LINK_STATUS:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PORT(id).link_status;
            break;
        case DMPS_DB_PORT_UNIDIR_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PORT(id).unidir_en;
            break;
        case DMPS_DB_PORT_RX_RST_HOLD:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PORT(id).rx_rst_hold;
            break;
        case DMPS_DB_PORT_IS_CTLE_RUN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PORT(id).is_ctle_running;
            break;
        case DMPS_DB_PORT_XPIPE_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PORT(id).xpipe_en;
            break;
        case DMPS_DB_PORT_MDIO_MAP:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).mdio_map;
            break;
        case DMPS_DB_PORT_PHY_MAP:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).phy_map;
            break;
        case DMPS_DB_PORT_DEVNO_MAP:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PORT(id).devno_map;
            break;
        case DMPS_DB_CHAN_CORE_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN(id).core_id;
            break;
        case DMPS_DB_CHAN_PP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN(id).pp_id + PP_NUM_PER_CORE * DMPS_DB_CHAN(id).core_id;
            break;
        case DMPS_DB_CHAN_DP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN(id).dp_id;
            break;
        case DMPS_DB_CHAN_TXQM_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN(id).txqm_id;
            break;
        case DMPS_DB_CHAN_SUB_CHAN_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint16*)p_value = DMPS_DB_CHAN(id).sub_chan_id;
            break;
        case DMPS_DB_CHAN_MAC_CLIENT_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint16*)p_value = DMPS_DB_CHAN(id).mac_client_id;
            break;
        case DMPS_DB_CHAN_SPEED_MODE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN(id).speed_mode;
            break;
        case DMPS_DB_CHAN_IS_RSV:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN(id).is_rsv;
            break;
        case DMPS_DB_CHAN_PRIO:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN(id).prio;
            break;
        case DMPS_DB_CHAN_SPEED_VALUE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_CHAN(id).speed_value;
            break;
        case DMPS_DB_CHAN_RX_CORE_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN_RX(id).core_id;
            break;
        case DMPS_DB_CHAN_RX_PP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN_RX(id).pp_id + PP_NUM_PER_CORE * DMPS_DB_CHAN_RX(id).core_id;
            break;
        case DMPS_DB_CHAN_RX_DP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN_RX(id).dp_id;
            break;
        case DMPS_DB_CHAN_RX_TXQM_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN_RX(id).txqm_id;
            break;
        case DMPS_DB_CHAN_RX_SUB_CHAN_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint16*)p_value = DMPS_DB_CHAN_RX(id).sub_chan_id;
            break;
        case DMPS_DB_CHAN_RX_MAC_CLIENT_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint16*)p_value = DMPS_DB_CHAN_RX(id).mac_client_id;
            break;
        case DMPS_DB_CHAN_RX_SPEED_MODE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN_RX(id).speed_mode;
            break;
        case DMPS_DB_CHAN_RX_IS_RSV:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN_RX(id).is_rsv;
            break;
        case DMPS_DB_CHAN_RX_PRIO:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_CHAN_RX(id).prio;
            break;
        case DMPS_DB_CHAN_RX_SPEED_VALUE:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_CHAN_RX(id).speed_value;
            break;
        case DMPS_DB_MAC_SPEED:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_MAC(id).mac_speed;
            break;
        case DMPS_DB_MAC_GROUP_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_MAC(id).mac_group_id;
            break;
        case DMPS_DB_MAC_IDX:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_MAC(id).mac_idx;
            break;
        case DMPS_DB_MAC_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_MAC(id).en;
            break;
        case DMPS_DB_PSD_PLL_SEL:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PSD(id).pll_sel;
            break;
        case DMPS_DB_PSD_RATE_DIV:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PSD(id).rate_div;
            break;
        case DMPS_DB_PSD_BIT_WIDTH:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PSD(id).bit_width;
            break;
        case DMPS_DB_PSD_RX_POLARITY:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PSD(id).rx_polarity;
            break;
        case DMPS_DB_PSD_SUPPORT_SPEED:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PSD(id).support_speed;
            break;
        case DMPS_DB_PSD_SPEED:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint32*)p_value = DMPS_DB_PSD(id).serdes_speed;
            break;
        case DMPS_DB_PSD_TX_POLARITY:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PSD(id).tx_polarity;
            break;
        case DMPS_DB_PSD_OCS:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PSD(id).ocs;
            break;
        case DMPS_DB_PSD_LANE_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PSD(id).physical_lane_id;
            break;
        case DMPS_DB_PSD_IS_DYN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PSD(id).is_dyn;
            break;
        case DMPS_DB_LSD_LANE_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_LSD(id).logical_lane_id;
            break;
        case DMPS_DB_LSD_PCSL_IDX:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_LSD(id).pcs_l_idx;
            break;
        case DMPS_DB_LSD_HSS_ID:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_LSD(id).hss_id;
            break;
        case DMPS_DB_PCS_IDX:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PCS(id).pcs_idx;
            break;
        case DMPS_DB_PCS_RX_RST_EN:
            if(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, id))
            {
                return CTC_E_INVALID_PARAM;
            }
            *(uint8*)p_value = DMPS_DB_PCS(id).rx_rst_en;
            break;
        default:
            return CTC_E_INVALID_PARAM;
    }
    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_get_single_map(uint8 lchip, uint16 key_id[])
{
    uint8  type = DMPS_DB_TYPE_BUTT;
    sys_dmps_mapping_set_t* map_node = NULL;

    for(type = DMPS_DB_TYPE_PORT; type < DMPS_DB_TYPE_BUTT; type++)
    {
        SYS_CONDITION_CONTINUE(DMPS_INVALID_VALUE_U16 == key_id[type]);
        switch (type)
        {
            case DMPS_DB_TYPE_PORT:
                if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, key_id[type]))
                {
                    map_node = DMPS_DB_PORT(key_id[type]).map.node[0];
                }
                break;
            case DMPS_DB_TYPE_MAC:
                if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, key_id[type]))
                {
                    map_node = DMPS_DB_MAC(key_id[type]).map.node[0];
                }
                break;
            case DMPS_DB_TYPE_PSD:
                if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, key_id[type]))
                {
                    map_node = DMPS_DB_PSD(key_id[type]).map.node[0];
                }
                break;
            case DMPS_DB_TYPE_LSD:
                if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, key_id[type]))
                {
                    map_node = DMPS_DB_LSD(key_id[type]).map.node[0];
                }
                break;
            case DMPS_DB_TYPE_PCS:
                if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, key_id[type]))
                {
                    map_node = DMPS_DB_PCS(key_id[type]).map.node[0];
                }
                break;
            case DMPS_DB_TYPE_CHAN:
                if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, key_id[type]))
                {
                    map_node = DMPS_DB_CHAN(key_id[type]).map.node[0];
                }
                break;
            case DMPS_DB_TYPE_CHAN_RX:
                if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, key_id[type]))
                {
                    map_node = DMPS_DB_CHAN_RX(key_id[type]).map.node[0];
                }
                break;
        }

        SYS_CONDITION_CONTINUE(NULL == map_node);

        key_id[DMPS_DB_TYPE_PORT]    = map_node->dport;
        key_id[DMPS_DB_TYPE_MAC]     = map_node->mac_id;
        key_id[DMPS_DB_TYPE_PSD]     = map_node->psd;
        key_id[DMPS_DB_TYPE_LSD]     = map_node->lsd;
        key_id[DMPS_DB_TYPE_PCS]     = map_node->pcs_id;
        key_id[DMPS_DB_TYPE_CHAN]    = map_node->chan_id;
        key_id[DMPS_DB_TYPE_CHAN_RX] = map_node->chan_rx_id;

        return CTC_E_NONE;
    }

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_get_map(uint8 lchip, uint8 db_type, uint16 key_id[], sys_dmps_mapping_search_info_t* p_map)
{
    uint8  type = DMPS_DB_TYPE_BUTT;
    
    CTC_PTR_VALID_CHECK(p_map);
    sal_memset(p_map, 0, sizeof(sys_dmps_mapping_search_info_t));
    p_map->type = db_type;

    if(DMPS_INVALID_VALUE_U16 != key_id[db_type])
    {
        p_map->search_num = 1;
        p_map->search_list[0] = key_id[db_type];
    }
    else
    {
        for(type = DMPS_DB_TYPE_PORT; type < DMPS_DB_TYPE_BUTT; type++)
        {
            SYS_CONDITION_BREAK(DMPS_INVALID_VALUE_U16 != key_id[type]);
        }
        if(DMPS_DB_TYPE_BUTT <= type)
        {
            return CTC_E_NONE;
        }
        (void) _sys_usw_dmps_db_get_relative_id(lchip, type, key_id[type], db_type, &(p_map->search_num), p_map->search_list);
    }

    return CTC_E_NONE;
}


STATIC int32 _sys_usw_dmps_db_set_port_info(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info)
{
    uint8  db_idx = 0;
    sys_dmps_mapping_search_info_t map_info = {0};
    sys_dmps_mapping_set_t old_info = {{0}};
    sys_dmps_mapping_set_t new_info = {{0}};
    uint16 key_id[DMPS_DB_TYPE_BUTT] = {
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16,
        DMPS_INVALID_VALUE_U16
    };

    if (DB_ITEM_IGNORE != p_upt_info->upt_map)
    {
        old_info.dport      = p_upt_info->old_dport;
        old_info.chan_id    = p_upt_info->old_chan_id;
        old_info.chan_rx_id = p_upt_info->old_chan_rx_id;
        old_info.mac_id     = p_upt_info->old_mac_id;
        old_info.pcs_id     = p_upt_info->old_pcs_id;
        old_info.lsd        = p_upt_info->old_logic_serdes;
        old_info.psd        = p_upt_info->old_physic_serdes;

        new_info.dport      = p_upt_info->dport;
        new_info.chan_id    = p_upt_info->chan_id;
        new_info.chan_rx_id = p_upt_info->chan_rx_id;
        new_info.mac_id     = p_upt_info->mac_id;
        new_info.pcs_id     = p_upt_info->pcs_id;
        new_info.lsd        = p_upt_info->logic_serdes;
        new_info.psd        = p_upt_info->physic_serdes;

        CTC_ERROR_RETURN(_sys_usw_dmps_db_mapping_update_node(lchip, &old_info, &new_info));
    }

    key_id[DMPS_DB_TYPE_PORT]    = p_upt_info->dport;
    key_id[DMPS_DB_TYPE_MAC]     = p_upt_info->mac_id;
    key_id[DMPS_DB_TYPE_PSD]     = p_upt_info->physic_serdes;
    key_id[DMPS_DB_TYPE_LSD]     = p_upt_info->logic_serdes;
    key_id[DMPS_DB_TYPE_PCS]     = p_upt_info->pcs_id;
    key_id[DMPS_DB_TYPE_CHAN]    = p_upt_info->chan_id;
    key_id[DMPS_DB_TYPE_CHAN_RX] = p_upt_info->chan_rx_id;

    /*2. property parser*/
    /*2.1 dport property*/
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_map(lchip, DMPS_DB_TYPE_PORT, key_id, &map_info));
    for(db_idx = 0; db_idx < map_info.search_num; db_idx++)
    {
        if(DB_ITEM_IGNORE != p_upt_info->upt_port_idx)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).port_idx = p_upt_info->port_idx;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_port_type)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).port_type = p_upt_info->port_type;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_if_type)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).if_type = p_upt_info->if_type;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_if_mode)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).if_mode = p_upt_info->if_mode;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_fec_type)
        {
             DMPS_DB_PORT(map_info.search_list[db_idx]).fec_type = p_upt_info->fec_type;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_an_fec)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_fec = p_upt_info->an_fec;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_mdio_map)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).mdio_map = p_upt_info->mdio_map;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_phy_map)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).phy_map = p_upt_info->phy_map;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_devno_map)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).devno_map = p_upt_info->devno_map;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_dport_is_rsv)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).is_rsv = p_upt_info->dport_is_rsv;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_an_mode)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_mode = p_upt_info->an_mode;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_an_en)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_en = p_upt_info->an_en;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_old_an_stat)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).old_cl73_status = p_upt_info->old_an_stat;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_link_intr_en)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).link_intr_en = p_upt_info->link_intr_en;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_link_status)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).link_status = p_upt_info->link_status;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_unidir_en)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).unidir_en = p_upt_info->unidir_en;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_rst_hold)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).rx_rst_hold = p_upt_info->rx_rst_hold;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_ctle_run)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).is_ctle_running = p_upt_info->ctle_run;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_xpipe_en)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).xpipe_en = p_upt_info->xpipe_en;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_bp_ability0)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_ability.base_ability0 = p_upt_info->bp_ability0;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_bp_ability1)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_ability.base_ability1 = p_upt_info->bp_ability1;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_np0_ability0)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_ability.np0_ability0 = p_upt_info->np0_ability0;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_np0_ability1)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_ability.np0_ability1 = p_upt_info->np0_ability1;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_np1_ability0)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_ability.np1_ability0 = p_upt_info->np1_ability0;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_np1_ability1)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).an_ability.np1_ability1 = p_upt_info->np1_ability1;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_is_an_first)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).is_an_first = p_upt_info->is_an_first;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_link_fsm)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).link_fsm = p_upt_info->link_fsm;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_link_mode)
        {
            DMPS_DB_PORT(map_info.search_list[db_idx]).link_mode = p_upt_info->link_mode;
        }
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    }

    /*2.2 chan property*/
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_map(lchip, DMPS_DB_TYPE_CHAN, key_id, &map_info));
    for(db_idx = 0; db_idx < map_info.search_num; db_idx++)
    {
        if(DB_ITEM_IGNORE != p_upt_info->upt_speed_mode)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).speed_mode = p_upt_info->speed_mode;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_chan_is_rsv)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).is_rsv = p_upt_info->chan_is_rsv;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_prio)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).prio = p_upt_info->prio;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_sub_chan)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).sub_chan_id = p_upt_info->sub_chan;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_mac_client)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).mac_client_id = p_upt_info->mac_client;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_core)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).core_id = p_upt_info->core;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_pp)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).pp_id = p_upt_info->pp;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_dp)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).dp_id = p_upt_info->dp;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_txqm)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).txqm_id = p_upt_info->txqm;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_speed_value)
        {
            DMPS_DB_CHAN(map_info.search_list[db_idx]).speed_value = p_upt_info->speed_value;
        }
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN, 1);
    }

    /*2.3 chan rx property*/
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_map(lchip, DMPS_DB_TYPE_CHAN_RX, key_id, &map_info));
    for(db_idx = 0; db_idx < map_info.search_num; db_idx++)
    {
        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_speed_mode)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).speed_mode = p_upt_info->rx_speed_mode;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_chan_is_rsv)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).is_rsv = p_upt_info->rx_chan_is_rsv;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_prio)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).prio = p_upt_info->rx_prio;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_sub_chan)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).sub_chan_id = p_upt_info->rx_sub_chan;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_mac_client)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).mac_client_id = p_upt_info->rx_mac_client;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_core)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).core_id = p_upt_info->rx_core;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_pp)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).pp_id = p_upt_info->rx_pp;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_dp)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).dp_id = p_upt_info->rx_dp;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_txqm)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).txqm_id = p_upt_info->rx_txqm;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_speed_value)
        {
            DMPS_DB_CHAN_RX(map_info.search_list[db_idx]).speed_value = p_upt_info->rx_speed_value;
        }
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN_RX, 1);
    }

    /*2.4 mac property*/
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_map(lchip, DMPS_DB_TYPE_MAC, key_id, &map_info));
    for(db_idx = 0; db_idx < map_info.search_num; db_idx++)
    {
        if(DB_ITEM_IGNORE != p_upt_info->upt_mac_speed)
        {
            DMPS_DB_MAC(map_info.search_list[db_idx]).mac_speed = p_upt_info->mac_speed;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_mac_group)
        {
            DMPS_DB_MAC(map_info.search_list[db_idx]).mac_group_id = p_upt_info->mac_group;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_mac_idx)
        {
            DMPS_DB_MAC(map_info.search_list[db_idx]).mac_idx = p_upt_info->mac_idx;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_mac_en)
        {
            DMPS_DB_MAC(map_info.search_list[db_idx]).en = p_upt_info->mac_en;
        }
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAC, 1);
    }

    /*2.5 pcs property*/
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_map(lchip, DMPS_DB_TYPE_PCS, key_id, &map_info));
    for(db_idx = 0; db_idx < map_info.search_num; db_idx++)
    {
        if(DB_ITEM_IGNORE != p_upt_info->upt_pcs_idx)
        {
            DMPS_DB_PCS(map_info.search_list[db_idx]).pcs_idx = p_upt_info->pcs_idx;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_rst_en)
        {
            DMPS_DB_PCS(map_info.search_list[db_idx]).rx_rst_en = p_upt_info->rx_rst_en;
        }
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PCS, 1);
    }

    /*2.6 logical serdes property*/
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_map(lchip, DMPS_DB_TYPE_LSD, key_id, &map_info));
    for(db_idx = 0; db_idx < map_info.search_num; db_idx++)
    {
        if(DB_ITEM_IGNORE != p_upt_info->upt_logic_lane)
        {
            DMPS_DB_LSD(map_info.search_list[db_idx]).logical_lane_id = p_upt_info->logic_lane;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_pcsl_idx)
        {
            DMPS_DB_LSD(map_info.search_list[db_idx]).pcs_l_idx = p_upt_info->pcsl_idx;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_hss_id)
        {
            DMPS_DB_LSD(map_info.search_list[db_idx]).hss_id = p_upt_info->hss_id;
        }
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_LSD, 1);
    }

    /*2.7 physical serdes property*/
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_map(lchip, DMPS_DB_TYPE_PSD, key_id, &map_info));
    for(db_idx = 0; db_idx < map_info.search_num; db_idx++)
    {
        if(DB_ITEM_IGNORE != p_upt_info->upt_is_dyn)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).is_dyn = p_upt_info->is_dyn;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rx_pol)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).rx_polarity = p_upt_info->rx_pol;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_tx_pol)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).tx_polarity = p_upt_info->tx_pol;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_support_speed)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).support_speed = p_upt_info->support_speed;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_curr_speed)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).serdes_speed = p_upt_info->curr_speed;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_ocs)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).ocs = p_upt_info->ocs;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_physic_lane)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).physical_lane_id = p_upt_info->physic_lane;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_rate_div)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).rate_div = p_upt_info->rate_div;
        }

        if(DB_ITEM_IGNORE != p_upt_info->upt_bit_width)
        {
            DMPS_DB_PSD(map_info.search_list[db_idx]).bit_width = p_upt_info->bit_width;
        }

        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD, 1);
    }

    return CTC_E_NONE;
}

STATIC int32 _sys_usw_dmps_db_get_port_info(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info)
{
    uint8  type = DMPS_DB_TYPE_BUTT;
    uint8  valid[DMPS_DB_TYPE_BUTT]  = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
    uint16 key_id[DMPS_DB_TYPE_BUTT] = {
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16, 
        DMPS_INVALID_VALUE_U16
    };

    key_id[DMPS_DB_TYPE_PORT]    = p_upt_info->dport;
    key_id[DMPS_DB_TYPE_MAC]     = p_upt_info->mac_id;
    key_id[DMPS_DB_TYPE_PSD]     = p_upt_info->physic_serdes;
    key_id[DMPS_DB_TYPE_LSD]     = p_upt_info->logic_serdes;
    key_id[DMPS_DB_TYPE_PCS]     = p_upt_info->pcs_id;
    key_id[DMPS_DB_TYPE_CHAN]    = p_upt_info->chan_id;
    key_id[DMPS_DB_TYPE_CHAN_RX] = p_upt_info->chan_rx_id;

    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_single_map(lchip, key_id));

    if((DMPS_INVALID_VALUE_U16 == key_id[DMPS_DB_TYPE_PORT]) && (DMPS_INVALID_VALUE_U16 == key_id[DMPS_DB_TYPE_MAC]) && 
       (DMPS_INVALID_VALUE_U16 == key_id[DMPS_DB_TYPE_PSD]) && (DMPS_INVALID_VALUE_U16 == key_id[DMPS_DB_TYPE_LSD]) && 
       (DMPS_INVALID_VALUE_U16 == key_id[DMPS_DB_TYPE_PCS]) && (DMPS_INVALID_VALUE_U16 == key_id[DMPS_DB_TYPE_CHAN]) &&
       (DMPS_INVALID_VALUE_U16 == key_id[DMPS_DB_TYPE_CHAN_RX]))
    {
        return CTC_E_INVALID_PARAM;
    }

    p_upt_info->dport         = key_id[DMPS_DB_TYPE_PORT];
    p_upt_info->mac_id        = key_id[DMPS_DB_TYPE_MAC];
    p_upt_info->physic_serdes = key_id[DMPS_DB_TYPE_PSD];
    p_upt_info->logic_serdes  = key_id[DMPS_DB_TYPE_LSD];
    p_upt_info->pcs_id        = key_id[DMPS_DB_TYPE_PCS];
    p_upt_info->chan_id       = key_id[DMPS_DB_TYPE_CHAN];
    p_upt_info->chan_rx_id    = key_id[DMPS_DB_TYPE_CHAN_RX];

    for(type = DMPS_DB_TYPE_PORT; type < DMPS_DB_TYPE_BUTT; type++)
    {
        valid[type] = (_sys_usw_dmps_db_is_usable_id(lchip, type, key_id[type])) ? TRUE : FALSE;
    }

    /*get property*/
    if(DB_ITEM_UPDATE == p_upt_info->upt_port_idx)
    {
        p_upt_info->port_idx = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).port_idx : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_port_type)
    {
        p_upt_info->port_type = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).port_type : SYS_DMPS_MAX_PORT_TYPE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_if_type)
    {
        p_upt_info->if_type = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).if_type : CTC_PORT_IF_NONE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_if_mode)
    {
        p_upt_info->if_mode = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).if_mode : CTC_CHIP_MAX_SERDES_MODE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_fec_type)
    {
        p_upt_info->fec_type = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).fec_type : CTC_PORT_FEC_TYPE_NONE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_an_fec)
    {
        p_upt_info->an_fec = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_fec : ((1 << CTC_PORT_FEC_TYPE_RS) & (1 << CTC_PORT_FEC_TYPE_BASER));
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_dport_is_rsv)
    {
        p_upt_info->dport_is_rsv = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).is_rsv : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_an_mode)
    {
        p_upt_info->an_mode = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_mode : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_mdio_map)
    {
        p_upt_info->mdio_map = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).mdio_map : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_phy_map)
    {
        p_upt_info->phy_map = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).phy_map : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_devno_map)
    {
        p_upt_info->devno_map = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).devno_map : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_bp_ability0)
    {
        p_upt_info->bp_ability0 = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_ability.base_ability0 : 0;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_bp_ability1)
    {
        p_upt_info->bp_ability1 = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_ability.base_ability1 : 0;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_np0_ability0)
    {
        p_upt_info->np0_ability0 = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_ability.np0_ability0 : 0;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_np0_ability1)
    {
        p_upt_info->np0_ability1 = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_ability.np0_ability1 : 0;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_np1_ability0)
    {
        p_upt_info->np1_ability0 = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_ability.np1_ability0 : 0;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_np1_ability1)
    {
        p_upt_info->np1_ability1 = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_ability.np1_ability1 : 0;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_an_en)
    {
        p_upt_info->an_en = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).an_en : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_old_an_stat)
    {
        p_upt_info->old_an_stat = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).old_cl73_status : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_link_intr_en)
    {
        p_upt_info->link_intr_en = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).link_intr_en : TRUE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_link_status)
    {
        p_upt_info->link_status = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).link_status : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_unidir_en)
    {
        p_upt_info->unidir_en = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).unidir_en : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_rst_hold)
    {
        p_upt_info->rx_rst_hold = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).rx_rst_hold : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_ctle_run)
    {
        p_upt_info->ctle_run = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).is_ctle_running : TRUE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_xpipe_en)
    {
        p_upt_info->xpipe_en = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).xpipe_en : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_is_an_first)
    {
        p_upt_info->is_an_first = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).is_an_first : 0;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_link_fsm)
    {
        p_upt_info->link_fsm = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).link_fsm : PMA_RX_ERROR;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_link_mode)
    {
        p_upt_info->link_mode = valid[DMPS_DB_TYPE_PORT] ? 
            DMPS_DB_PORT(key_id[DMPS_DB_TYPE_PORT]).link_mode : LINK_MODE_BUTT;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_speed_mode)
    {
        p_upt_info->speed_mode = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).speed_mode : SYS_PORT_SPEED_MAX;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_chan_is_rsv)
    {
        p_upt_info->chan_is_rsv = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).is_rsv : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_prio)
    {
        p_upt_info->prio = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).prio : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_sub_chan)
    {
        p_upt_info->sub_chan = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).sub_chan_id : DMPS_INVALID_VALUE_U16;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_mac_client)
    {
        p_upt_info->mac_client = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).mac_client_id : DMPS_INVALID_VALUE_U16;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_core)
    {
        p_upt_info->core = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).core_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_pp)
    {
        p_upt_info->pp = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).pp_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_dp)
    {
        p_upt_info->dp = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).dp_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_txqm)
    {
        p_upt_info->txqm = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).txqm_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_speed_value)
    {
        p_upt_info->speed_value = valid[DMPS_DB_TYPE_CHAN] ? 
            DMPS_DB_CHAN(key_id[DMPS_DB_TYPE_CHAN]).speed_value : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_speed_mode)
    {
        p_upt_info->rx_speed_mode = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).speed_mode : CTC_PORT_SPEED_MAX;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_chan_is_rsv)
    {
        p_upt_info->rx_chan_is_rsv = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).is_rsv : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_prio)
    {
        p_upt_info->rx_prio = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).prio : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_sub_chan)
    {
        p_upt_info->rx_sub_chan = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).sub_chan_id : DMPS_INVALID_VALUE_U16;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_mac_client)
    {
        p_upt_info->rx_mac_client = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).mac_client_id : DMPS_INVALID_VALUE_U16;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_core)
    {
        p_upt_info->rx_core = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).core_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_pp)
    {
        p_upt_info->rx_pp = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).pp_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_dp)
    {
        p_upt_info->rx_dp = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).dp_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_txqm)
    {
        p_upt_info->rx_txqm = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).txqm_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_speed_value)
    {
        p_upt_info->rx_speed_value = valid[DMPS_DB_TYPE_CHAN_RX] ? 
            DMPS_DB_CHAN_RX(key_id[DMPS_DB_TYPE_CHAN_RX]).speed_value : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_mac_speed)
    {
        p_upt_info->mac_speed = valid[DMPS_DB_TYPE_MAC] ? 
            DMPS_DB_MAC(key_id[DMPS_DB_TYPE_MAC]).mac_speed : CTC_PORT_SPEED_MAX;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_mac_group)
    {
        p_upt_info->mac_group = valid[DMPS_DB_TYPE_MAC] ? 
            DMPS_DB_MAC(key_id[DMPS_DB_TYPE_MAC]).mac_group_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_mac_idx)
    {
        p_upt_info->mac_idx = valid[DMPS_DB_TYPE_MAC] ? 
            DMPS_DB_MAC(key_id[DMPS_DB_TYPE_MAC]).mac_idx : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_mac_en)
    {
        p_upt_info->mac_en = valid[DMPS_DB_TYPE_MAC] ? 
            DMPS_DB_MAC(key_id[DMPS_DB_TYPE_MAC]).en : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_pcs_idx)
    {
        p_upt_info->pcs_idx = valid[DMPS_DB_TYPE_PCS] ? 
            DMPS_DB_PCS(key_id[DMPS_DB_TYPE_PCS]).pcs_idx : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_rst_en)
    {
        p_upt_info->rx_rst_en = valid[DMPS_DB_TYPE_PCS] ? 
            DMPS_DB_PCS(key_id[DMPS_DB_TYPE_PCS]).rx_rst_en : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_logic_lane)
    {
        p_upt_info->logic_lane = valid[DMPS_DB_TYPE_LSD] ? 
            DMPS_DB_LSD(key_id[DMPS_DB_TYPE_LSD]).logical_lane_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_pcsl_idx)
    {
        p_upt_info->pcsl_idx = valid[DMPS_DB_TYPE_LSD] ? 
            DMPS_DB_LSD(key_id[DMPS_DB_TYPE_LSD]).pcs_l_idx : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_hss_id)
    {
        p_upt_info->hss_id = valid[DMPS_DB_TYPE_LSD] ? 
            DMPS_DB_LSD(key_id[DMPS_DB_TYPE_LSD]).hss_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_is_dyn)
    {
        p_upt_info->is_dyn = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).is_dyn : FALSE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rx_pol)
    {
        p_upt_info->rx_pol = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).rx_polarity : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_tx_pol)
    {
        p_upt_info->tx_pol = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).tx_polarity : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_support_speed)
    {
        p_upt_info->support_speed = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).support_speed : DMPS_INVALID_VALUE_U32;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_curr_speed)
    {
        p_upt_info->curr_speed = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).serdes_speed : SERDES_SPEED_MAX;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_ocs)
    {
        p_upt_info->ocs = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).ocs : CTC_CHIP_MAX_SERDES_OCS_MODE;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_physic_lane)
    {
        p_upt_info->physic_lane = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).physical_lane_id : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_rate_div)
    {
        p_upt_info->rate_div = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).rate_div : DMPS_INVALID_VALUE_U8;
    }
    if(DB_ITEM_UPDATE == p_upt_info->upt_bit_width)
    {
        p_upt_info->bit_width = valid[DMPS_DB_TYPE_PSD] ? 
            DMPS_DB_PSD(key_id[DMPS_DB_TYPE_PSD]).bit_width : DMPS_INVALID_VALUE_U8;
    }
  
    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_upt_info_init(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info)
{
    sal_memset(p_upt_info, 0, sizeof(sys_dmps_db_upt_info_t));

    p_upt_info->dport         = DMPS_INVALID_VALUE_U16;
    p_upt_info->chan_id       = DMPS_INVALID_VALUE_U16;
    p_upt_info->chan_rx_id    = DMPS_INVALID_VALUE_U16;
    p_upt_info->mac_id        = DMPS_INVALID_VALUE_U16;
    p_upt_info->pcs_id        = DMPS_INVALID_VALUE_U16;
    p_upt_info->logic_serdes  = DMPS_INVALID_VALUE_U16;
    p_upt_info->physic_serdes = DMPS_INVALID_VALUE_U16;

    p_upt_info->old_dport         = DMPS_INVALID_VALUE_U16;
    p_upt_info->old_chan_id       = DMPS_INVALID_VALUE_U16;
    p_upt_info->old_chan_rx_id    = DMPS_INVALID_VALUE_U16;
    p_upt_info->old_mac_id        = DMPS_INVALID_VALUE_U16;
    p_upt_info->old_pcs_id        = DMPS_INVALID_VALUE_U16;
    p_upt_info->old_logic_serdes  = DMPS_INVALID_VALUE_U16;
    p_upt_info->old_physic_serdes = DMPS_INVALID_VALUE_U16;

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_get_chan_info(uint8 lchip, sys_dmps_db_chan_info_t* chan_info, uint8 dir_bmp)
{
    uint16 chan_id = chan_info->chan_id;
    sys_dmps_db_upt_info_t port_info  = {0};

    CTC_ERROR_RETURN(_sys_usw_dmps_db_is_valid_id(lchip, GET_CHAN_TYPE_BY_DIR(dir_bmp), chan_id));

    CTC_ERROR_RETURN(_sys_usw_dmps_db_upt_info_init(lchip, &port_info));
    DMPS_DB_SET_MAP_INFO(port_info, GET_CHAN_ID_BY_DIR(dir_bmp) , chan_id);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_CORE_ID_BY_DIR(dir_bmp));
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_PP_ID_BY_DIR(dir_bmp));
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_DP_ID_BY_DIR(dir_bmp));
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_TXQM_ID_BY_DIR(dir_bmp));
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_SUB_CHAN_ID_BY_DIR(dir_bmp));
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_MAC_CLIENT_ID_BY_DIR(dir_bmp));
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_SPEED_MODE_BY_DIR(dir_bmp));
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_SPEED_VALUE_BY_DIR(dir_bmp));
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, GET_PRIO_BY_DIR(dir_bmp));
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_port_info(lchip, &port_info));
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_CORE_ID_BY_DIR(dir_bmp),       chan_info->core_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_PP_ID_BY_DIR(dir_bmp),         chan_info->pp_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_DP_ID_BY_DIR(dir_bmp),         chan_info->dp_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_TXQM_ID_BY_DIR(dir_bmp),       chan_info->txqm_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_SUB_CHAN_ID_BY_DIR(dir_bmp),   chan_info->sub_chan_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_MAC_CLIENT_ID_BY_DIR(dir_bmp), chan_info->mac_client_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_SPEED_MODE_BY_DIR(dir_bmp),    chan_info->speed_mode);
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_SPEED_VALUE_BY_DIR(dir_bmp),   chan_info->speed_value);
    DMPS_DB_GET_PROPERTY_INFO(port_info, GET_PRIO_BY_DIR(dir_bmp),          chan_info->prio);

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_api_get_com_info(uint8 lchip, uint16 lport, uint8 index, sys_port_info_t* p_port_info)
{
    uint8  core    = 0;
    uint8  num     = 0;
    uint16 dport   = 0;
    uint16 chan_id = 0;
    int32 ret      = CTC_E_NONE;
    uint16 chan_list[DMPS_MAX_NUM_PER_MODULE]  = {0};
    sys_dmps_db_upt_info_t port_info = {0};

    CTC_ERROR_RETURN(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    p_port_info->mac_id           = DMPS_INVALID_VALUE_U16;
    p_port_info->speed_mode       = CTC_PORT_SPEED_MAX;
    p_port_info->port_type        = SYS_DMPS_RSV_PORT;
    p_port_info->chan_id          = DMPS_INVALID_VALUE_U16;
    p_port_info->dp_id            = DMPS_INVALID_VALUE_U8;
    p_port_info->pp_id            = DMPS_INVALID_VALUE_U8;
    p_port_info->sub_chan_id      = DMPS_INVALID_VALUE_U16;
    p_port_info->mac_client_id    = DMPS_INVALID_VALUE_U16;
    p_port_info->rx_chan_id       = DMPS_INVALID_VALUE_U16;
    p_port_info->rx_sub_chan_id   = DMPS_INVALID_VALUE_U16;
    p_port_info->rx_mac_client_id = DMPS_INVALID_VALUE_U16;

    SYS_CONDITION_RETURN(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), CTC_E_NONE);
    CTC_MAX_VALUE_CHECK(lport, MCHIP_CAP(SYS_CAP_PORT_NUM_PER_CHIP) - 1);

    CTC_ERROR_RETURN(_sys_usw_dmps_db_upt_info_init(lchip, &port_info));
    DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_DPORT, dport);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_TYPE);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_SPEED_MODE);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_PP_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_DP_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_CORE_ID);
    ret = _sys_usw_dmps_db_get_port_info(lchip, &port_info);
    if (CTC_E_NONE != ret)
    {
        p_port_info->port_type = SYS_DMPS_RSV_PORT;
        return CTC_E_NONE;
    }

    DMPS_DB_GET_MAP_INFO(port_info, DMPS_DB_MAC_ID,                     p_port_info->mac_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_SPEED_MODE,       p_port_info->speed_mode);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_PORT_TYPE,             p_port_info->port_type);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_PP_ID,            p_port_info->pp_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_DP_ID,            p_port_info->dp_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_CORE_ID,          core);
    p_port_info->pp_id    += (PP_NUM_PER_CORE * core);

    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, DMPS_DB_TYPE_CHAN, &num, chan_list));
    chan_id = chan_list[index];
    if ((index < num) &&  (DMPS_INVALID_VALUE_U16 != chan_id))
    {
        if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, chan_id))
        {
            p_port_info->mac_client_id = DMPS_DB_CHAN(chan_id).mac_client_id;
            p_port_info->sub_chan_id   = DMPS_DB_CHAN(chan_id).sub_chan_id;
            p_port_info->chan_id       = chan_id;
        }
        else
        {
            p_port_info->mac_client_id = DMPS_INVALID_VALUE_U16;
            p_port_info->sub_chan_id   = DMPS_INVALID_VALUE_U16;
            p_port_info->chan_id       = DMPS_INVALID_VALUE_U16;
        }
    }

    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, DMPS_DB_TYPE_CHAN_RX, &num, chan_list));
    chan_id = chan_list[index];
    if ((index < num) &&  (DMPS_INVALID_VALUE_U16 != chan_id))
    {
        if (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, chan_id))
        {
            p_port_info->rx_mac_client_id = DMPS_DB_CHAN_RX(chan_id).mac_client_id;
            p_port_info->rx_sub_chan_id   = DMPS_DB_CHAN_RX(chan_id).sub_chan_id;
            p_port_info->rx_chan_id       = chan_id;
        }
        else
        {
            p_port_info->rx_mac_client_id = DMPS_INVALID_VALUE_U16;
            p_port_info->rx_sub_chan_id   = DMPS_INVALID_VALUE_U16;
            p_port_info->rx_chan_id       = DMPS_INVALID_VALUE_U16;
        }
    }

    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_api_get_port_info(uint8 lchip, uint16 lport, sys_port_api_dmps_info_t* p_port_info)
{
    uint8  cnt        = 0;
    uint8  core       = 0;
    uint8  rx_core    = 0;
    uint8  serdes_num = 0;
    uint16 dport      = 0;
    uint16 serdes[DMPS_MAX_NUM_PER_MODULE] = {0};
    sys_dmps_db_upt_info_t port_info       = {0};

    CTC_ERROR_RETURN(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    SYS_CONDITION_RETURN(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), CTC_E_NONE);

    sal_memset(serdes, SYS_DMPS_INVALID_U8, DMPS_MAX_NUM_PER_MODULE * sizeof(uint16));

    (void) _sys_usw_dmps_db_upt_info_init(lchip, &port_info);
    DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_DPORT,  dport);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_TYPE);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_SPEED_MODE);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_CORE_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_PP_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_DP_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_SUB_CHAN_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_RX_CORE_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_RX_PP_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_RX_DP_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_RX_SUB_CHAN_ID);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_MAC_EN);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_AN_EN);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_IF_TYPE);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_MDIO_MAP);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_PHY_MAP);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_DEVNO_MAP);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_AN_MODE);
    DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_PORT_IF_MODE);
    CTC_ERROR_RETURN(_sys_usw_dmps_db_get_port_info(lchip, &port_info));
    DMPS_DB_GET_MAP_INFO(port_info, DMPS_DB_MAC_ID,                   p_port_info->mac_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_PORT_TYPE,           p_port_info->port_type);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_SPEED_MODE,     p_port_info->speed_mode);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_MAC_EN,              p_port_info->mac_en);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_PORT_AN_EN,          p_port_info->auto_neg_en);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_PORT_IF_TYPE,        p_port_info->interface_type);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_PORT_AN_MODE,        p_port_info->auto_neg_mode);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_PORT_IF_MODE,        p_port_info->serdes_info.serdes_mode);
    DMPS_DB_GET_MAP_INFO(port_info, DMPS_DB_CHAN_ID,                  p_port_info->chan_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_CORE_ID,        core);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_PP_ID,          p_port_info->pp_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_DP_ID,          p_port_info->dp_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_SUB_CHAN_ID,    p_port_info->sub_chan_id);
    DMPS_DB_GET_MAP_INFO(port_info, DMPS_DB_CHAN_RX_ID,               p_port_info->chan_rx_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_CORE_ID,     rx_core);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_PP_ID,       p_port_info->rx_pp_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_DP_ID,       p_port_info->rx_dp_id);
    DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_SUB_CHAN_ID, p_port_info->rx_sub_chan_id);

    (void) _sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, DMPS_DB_TYPE_PSD, &serdes_num, serdes);

    if (serdes_num > DMPS_MAX_NUM_PER_MODULE)
    {
        return CTC_E_INVALID_PARAM;
    }

    p_port_info->serdes_info.serdes_num = serdes_num;

    for (cnt = 0; cnt < serdes_num; cnt++)
    {
        p_port_info->serdes_info.serdes_id[cnt] = serdes[cnt];
    }

    p_port_info->pp_id    = SYS_DMPS_GET_CHIP_PP(core, p_port_info->pp_id);
    p_port_info->rx_pp_id = SYS_DMPS_GET_CHIP_PP(rx_core, p_port_info->rx_pp_id);


    return CTC_E_NONE;
}

STATIC int32
_sys_usw_dmps_db_set_internal_port_info(uint8 lchip, sys_internal_port_info_t* p_port_info)
{
    uint16 mac_client  = DMPS_INVALID_VALUE_U16;
    uint16 dport       = DMPS_INVALID_VALUE_U16;
    uint16 old_chan    = DMPS_INVALID_VALUE_U16;
    uint32 pp_per_core = DMPS_PP_NUM_PER_CORE;
    uint32 speed_value = 0;
    sys_dmps_db_upt_info_t port_info = {0};

    if (0 == pp_per_core)
    {
        return CTC_E_INVALID_CHIP_ID;
    }

    if (p_port_info->lport < DMPS_MAX_PORT_NUM)
    {
        dport = p_port_info->lport;
        p_usw_dmps_db_master[lchip]->ext_lport_map[p_port_info->lport] = dport;
    }
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER, 1);
    if (DRV_IS_AT(lchip))
    {
        if ((SYS_DMPS_ILOOP_PORT == p_port_info->port_type) || (SYS_DMPS_ELOOP_PORT == p_port_info->port_type))
        {
            mac_client = 33;
        }
        else if ((SYS_DMPS_OAM_PORT == p_port_info->port_type) || (SYS_DMPS_DMA_PORT == p_port_info->port_type)
            || (SYS_DMPS_CPU_MAC_PORT == p_port_info->port_type) || (SYS_DMPS_CPUMAC_NETWORK_PORT == p_port_info->port_type))
        {
            mac_client = 32;
        }
    }
    else if(DRV_IS_TMG(lchip))
    {
        mac_client = p_port_info->dp_mac_client;
    }

    SYS_USW_GET_SPEED_VALUE(p_port_info->speed_mode, SYS_DMPS_FEC_TYPE_NONE, CTC_CHIP_SERDES_OCS_MODE_NONE, speed_value);

    CTC_ERROR_RETURN(_sys_usw_dmps_db_upt_info_init(lchip, &port_info));
    DMPS_DB_SET_MAP_UPDATE(port_info);
    if (p_port_info->is_update)
    {
        (void) _sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_CHAN, &old_chan);
        DMPS_DB_SET_MAP_UPDATE(port_info);
        DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_OLD_DPORT,              dport);
        DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_OLD_CHAN_ID,            old_chan);
        DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_OLD_CHAN_RX_ID,         old_chan);
    }
    DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_DPORT,                      dport);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_PORT_TYPE,             p_port_info->port_type);
    DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_CHAN_ID,                    p_port_info->chan_id);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_SUB_CHAN_ID,      p_port_info->sub_chan_id);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_CORE_ID,          (p_port_info->pp_id / pp_per_core));
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_PP_ID,            (p_port_info->pp_id % pp_per_core));
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_DP_ID,            p_port_info->dp_id);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_SPEED_MODE,       p_port_info->speed_mode);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_MAC_CLIENT_ID,    mac_client);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_SPEED_VALUE,      speed_value);
    DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_CHAN_RX_ID,                 p_port_info->chan_id);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_SUB_CHAN_ID,   p_port_info->sub_chan_id);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_CORE_ID,       (p_port_info->pp_id / pp_per_core));
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_PP_ID,         (p_port_info->pp_id % pp_per_core));
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_DP_ID,         p_port_info->dp_id);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_SPEED_MODE,    p_port_info->speed_mode);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_MAC_CLIENT_ID, mac_client);
    DMPS_DB_SET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_RX_SPEED_VALUE,   speed_value);
    
    CTC_ERROR_RETURN(_sys_usw_dmps_db_set_port_info(lchip, &port_info));

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_port_property(uint8 lchip, sys_dmps_port_info_t* port_info, uint8 port_prop, void *p_value)
{
    int32 ret = CTC_E_NONE;
    uint32 *p_tmp_value = NULL;
    uint16 dport = 0;
    uint16 lport = 0;
    uint32 val_u32 = 0;
    uint16 val_u16 = 0;
    uint16 serdes_u16[DMPS_MAX_NUM_PER_MODULE] = {0};
    uint16 chan_list[DMPS_MAX_NUM_PER_MODULE]  = {0};
    uint8  val_u8 = 0;
    uint8  index  = 0;
    uint8  idx = 0;
    uint8  num = 0;
    uint8  dir_bmp   = 0;
    uint8  port_type = 0;
    uint8  if_type   = 0;
    uint32 speed_value = 0;
    sys_port_api_serdes_info_t *p_serdes_info = NULL;

    CTC_PTR_VALID_CHECK(p_value);
    CTC_PTR_VALID_CHECK(port_info);

    lport   = port_info->lport;
    index   = port_info->index;
    dir_bmp = port_info->dir_bmp;

    SYS_DMPS_DB_LOCK(lchip);

    p_tmp_value = (uint32*) p_value;
    ret = _sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport);
    if(CTC_E_NONE != ret)
    {
        if ((SYS_PORT_API_DMPS_PROP_PORT_TYPE == port_prop)
         || (SYS_PORT_API_DMPS_PROP_PHY_PORT_TYPE == port_prop))
        {
            *p_tmp_value = SYS_DMPS_RSV_PORT;
        }
        SYS_DMPS_DB_UNLOCK(lchip);
        return CTC_E_NONE;
    }

    switch(port_prop)
    {
    case SYS_PORT_API_DMPS_PROP_MAC_ID:
    case SYS_PORT_API_DMPS_PROP_MAC_STATS_ID:
        ret = _sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_TYPE, dport, &port_type);
        if((CTC_E_NONE != ret) || ((SYS_DMPS_NETWORK_PORT != port_type) && (!SYS_USW_IS_CPUMAC_PORT(port_type))))
        {
            *p_tmp_value = DMPS_INVALID_VALUE_U32;
        }
        else
        {
            ret = _sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_MAC, &val_u16);
            *p_tmp_value = (CTC_E_NONE == ret) ? val_u16 : DMPS_INVALID_VALUE_U16;
        }
        break;

    case SYS_PORT_API_DMPS_PROP_CHAN_ID:
    case SYS_PORT_API_DMPS_PROP_PHY_PORT_CHAN_ID:
        ret = _sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_TYPE, dport, &port_type);
        if((CTC_E_NONE != ret) || (SYS_DMPS_RSV_PORT == port_type))
        {
            *p_tmp_value = DMPS_INVALID_VALUE_U16;
        }
        else
        {
            ret = _sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, GET_CHAN_TYPE_BY_DIR(dir_bmp), &num, chan_list);
            *p_tmp_value = ((CTC_E_NONE == ret) && (index < num)) ? chan_list[index] : DMPS_INVALID_VALUE_U16;
        }
        break;

    case SYS_PORT_API_DMPS_PROP_SUB_CHAN_ID:
        ret = _sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, GET_CHAN_TYPE_BY_DIR(dir_bmp), &num, chan_list);
        *p_tmp_value = ((CTC_E_NONE == ret) && (index < num)) ? GET_CHAN_DB_BY_DIR(dir_bmp, chan_list[index], sub_chan_id) : DMPS_INVALID_VALUE_U16;
        break;

    case SYS_PORT_API_DMPS_PROP_PP_ID:
        ret = _sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_TYPE, dport, &port_type);
        ret = ret?ret:_sys_usw_dmps_db_get_dport_relative_id(lchip, dport, GET_CHAN_TYPE_BY_DIR(dir_bmp), &val_u16);
        val_u32 = val_u16;
        ret = ret?ret:_sys_usw_dmps_db_get_internal_prop(lchip, GET_PP_ID_BY_DIR(dir_bmp), val_u32, &val_u8);
        *p_tmp_value = (CTC_E_NONE != ret) ? DMPS_INVALID_VALUE_U8 : val_u8;
        if ((SYS_DMPS_RSV_PORT == port_type) && (CTC_E_NONE != ret))
        {
            *p_tmp_value = 0;
        }
        break;

    case SYS_PORT_API_DMPS_PROP_DP_ID:
        ret = _sys_usw_dmps_db_get_dport_relative_id(lchip, dport, GET_CHAN_TYPE_BY_DIR(dir_bmp), &val_u16);
        val_u32 = val_u16;
        ret = ret?ret:_sys_usw_dmps_db_get_internal_prop(lchip, GET_DP_ID_BY_DIR(dir_bmp), val_u32, &val_u8);
        *p_tmp_value = (CTC_E_NONE != ret) ? DMPS_INVALID_VALUE_U8 : val_u8;
        break;

    case SYS_PORT_API_DMPS_PROP_PORT_TYPE:
    case SYS_PORT_API_DMPS_PROP_PHY_PORT_TYPE:
        ret = _sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_TYPE, dport, &port_type);
        *p_tmp_value = (CTC_E_NONE != ret) ? DMPS_INVALID_VALUE_U8 : port_type;
        break;

    case SYS_PORT_API_DMPS_PROP_SPEED_MODE:
        ret = _sys_usw_dmps_db_get_dport_relative_id(lchip, dport, GET_CHAN_TYPE_BY_DIR(dir_bmp), &val_u16);
        val_u32 = val_u16;
        ret = ret?ret:_sys_usw_dmps_db_get_internal_prop(lchip, GET_SPEED_MODE_BY_DIR(dir_bmp), val_u32, &val_u8);
        *p_tmp_value = (CTC_E_NONE != ret) ? DMPS_INVALID_VALUE_U8 : val_u8;
        break;

    case SYS_PORT_API_DMPS_PROP_SERDES:
        p_serdes_info = (sys_port_api_serdes_info_t*)p_value;
        ret = _sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_TYPE, dport, &port_type);
        if((CTC_E_NONE != ret) || ((SYS_DMPS_NETWORK_PORT != port_type) && (SYS_DMPS_INACTIVE_NETWORK_PORT != port_type)))
        {
            p_serdes_info->serdes_mode = DMPS_INVALID_VALUE_U8;
            p_serdes_info->serdes_num = 0;
            for(idx = 0; idx < 8; idx++)
            {
                p_serdes_info->serdes_id[idx] = DMPS_INVALID_VALUE_U16;
            }
        }
        else
        {
            CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, DMPS_DB_TYPE_PSD, 
                &val_u8, serdes_u16));
            for(idx = 0; idx < val_u8; idx++)
            {
                p_serdes_info->serdes_id[idx] = serdes_u16[idx];
            }
            p_serdes_info->serdes_num = val_u8;
            CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_IF_MODE, dport, &val_u8));
            p_serdes_info->serdes_mode = val_u8;
        }
        break;

    case SYS_PORT_API_DMPS_PROP_SERDES_LOGIC:
        p_serdes_info = (sys_port_api_serdes_info_t*)p_value;
        ret = _sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_TYPE, dport, &port_type);
        if((CTC_E_NONE != ret) || ((SYS_DMPS_NETWORK_PORT != port_type) && (SYS_DMPS_INACTIVE_NETWORK_PORT != port_type)))
        {
            p_serdes_info->serdes_mode = DMPS_INVALID_VALUE_U8;
            p_serdes_info->serdes_num = 0;
            for(idx = 0; idx < 8; idx++)
            {
                p_serdes_info->serdes_id[idx] = DMPS_INVALID_VALUE_U8;
            }
        }
        else
        {
            CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, DMPS_DB_TYPE_LSD, 
                &val_u8, serdes_u16));
            for(idx = 0; idx < val_u8; idx++)
            {
                p_serdes_info->serdes_id[idx] = (uint8)serdes_u16[idx];
            }
            p_serdes_info->serdes_num = val_u8;
            CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_IF_MODE, dport, &val_u8));
            p_serdes_info->serdes_mode = val_u8;
        }
        break;

    case SYS_PORT_API_DMPS_PROP_WLAN_ENABLE:

        break;

    case SYS_PORT_API_DMPS_PROP_DOT1AE_ENABLE:

        break;

    case SYS_PORT_API_DMPS_PROP_TX_PRIVATE_INT_EN:

        break;

    case SYS_PORT_API_DMPS_PROP_GET_PHY_INST_ID:
        break;

    case SYS_PORT_API_DMPS_PROP_GET_DP_ASICINST_ID:
        break;

    case SYS_PORT_API_DMPS_PROP_MAC_ID_P:
        ret = _sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_TYPE, dport, &port_type);
        if((CTC_E_NONE != ret) || ((SYS_DMPS_NETWORK_PORT != port_type) && (!SYS_USW_IS_CPUMAC_PORT(port_type))))
        {
            *p_tmp_value = DMPS_INVALID_VALUE_U32;
        }
        else
        {
            *p_tmp_value = 0;
        }
        break;

    case SYS_PORT_API_DMPS_PROP_PHY_PORT_PMAC_CHAN_ID:
        *p_tmp_value = DMPS_INVALID_VALUE_U16;
        break;

    case SYS_PORT_API_DMPS_PROP_GET_MAC_INDEX:
        ret = _sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_MAC, &val_u16);
        ret = ret?ret:_sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_MAC_IDX, val_u16, &val_u8);
        *p_tmp_value = (CTC_E_NONE != ret) ? DMPS_INVALID_VALUE_U8 : val_u8;
        break;

    case SYS_PORT_API_DMPS_PROP_GET_SGMAC_INDEX:
        *p_tmp_value = 0;
        break;

    case SYS_PORT_API_DMPS_PROP_GET_PMAC_ID:
        ret = _sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, GET_CHAN_TYPE_BY_DIR(dir_bmp), &num, chan_list);
        *p_tmp_value = ((CTC_E_NONE == ret) && (index < num)) ? GET_CHAN_DB_BY_DIR(dir_bmp, chan_list[index], mac_client_id) : DMPS_INVALID_VALUE_U16;
        break;

    case SYS_PORT_API_DMPS_PROP_GET_PMAC_CHAN_ID:
        *p_tmp_value = DMPS_INVALID_VALUE_U16;
        break;

    case SYS_PORT_API_DMPS_PROP_GET_IF_TYPE:
        ret = _sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_PORT_IF_TYPE, dport, &if_type);
        if (CTC_E_NONE == ret)
        {
            *p_tmp_value = if_type;
        }
        break;

    case SYS_PORT_API_DMPS_PROP_SPEED_VALUE:
        ret = _sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_CHAN, &val_u16);
        ret = ret?ret:_sys_usw_dmps_db_get_internal_prop(lchip, DMPS_DB_CHAN_SPEED_VALUE, val_u16, &speed_value);
        if (CTC_E_NONE == ret)
        {
            *p_tmp_value = speed_value;
        }
        break;

    default:
        SYS_DMPS_DB_UNLOCK(lchip);
        return CTC_E_INVALID_PARAM;
    }

    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

uint16
sys_usw_dmps_db_get_lport_with_chan(uint8 lchip, uint8 dir_bmp, uint16 chan_id)
{
    uint16 lport[DMPS_MAX_NUM_PER_MODULE] = {DMPS_INVALID_VALUE_U16};

    SYS_DMPS_DB_LOCK(lchip);
    (void)_sys_usw_dmps_db_get_relative_id(lchip, GET_CHAN_TYPE_BY_DIR(dir_bmp), chan_id, DMPS_DB_TYPE_PORT, NULL, lport);
    SYS_DMPS_DB_UNLOCK(lchip);
    return lport[0];
}

uint16
sys_usw_dmps_db_get_lport_with_subchan(uint8 lchip, uint8 dir_bmp, uint8 core, uint8 pp, uint8 dp, uint8 sub_chan)
{
    uint16 lport[DMPS_MAX_NUM_PER_MODULE] = {DMPS_INVALID_VALUE_U16};
    uint16 chan_id = DMPS_INVALID_VALUE_U16;

    SYS_DMPS_DB_LOCK(lchip);
    for(chan_id = 0; chan_id < DMPS_MAX_CHAN_NUM; chan_id++)
    {
        if((core == GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, core_id)) && (pp == GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, pp_id)) && 
           (dp == GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, dp_id)) && (sub_chan == GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, sub_chan_id)))
        {
            break;
        }
    }
    if(chan_id < DMPS_MAX_CHAN_NUM)
    {
        (void)_sys_usw_dmps_db_get_relative_id(lchip, GET_CHAN_TYPE_BY_DIR(dir_bmp), chan_id, DMPS_DB_TYPE_PORT, NULL, lport);
    }
    SYS_DMPS_DB_UNLOCK(lchip);
    return lport[0];
}

uint16
sys_usw_dmps_db_get_lport_with_mac(uint8 lchip, uint16 mac_id)
{
    uint16 lport[8] = {DMPS_INVALID_VALUE_U16};
    SYS_DMPS_DB_LOCK(lchip);
    (void)_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_MAC, mac_id, DMPS_DB_TYPE_PORT, NULL, lport);
    SYS_DMPS_DB_UNLOCK(lchip);
    return lport[0];
}

int32
sys_usw_dmps_db_get_sub_chan_by_chan(uint8 lchip, uint8 dir_bmp, uint16 chan, 
                                uint16* sub_chan, uint8* pp_id, uint8* dp_id)
{
    int32 ret0 = CTC_E_NONE;
    SYS_DMPS_DB_LOCK(lchip);

    if(pp_id)
    {
        ret0 = _sys_usw_dmps_db_get_internal_prop(lchip, GET_PP_ID_BY_DIR(dir_bmp), chan, pp_id);
        if(CTC_E_NONE != ret0)
        {
            *pp_id = DMPS_INVALID_VALUE_U8;
        }
    }
    if(dp_id)
    {
        ret0 = _sys_usw_dmps_db_get_internal_prop(lchip, GET_DP_ID_BY_DIR(dir_bmp), chan, dp_id);
        if(CTC_E_NONE != ret0)
        {
            *dp_id = DMPS_INVALID_VALUE_U8;
        }
    }
    if(sub_chan)
    {
        ret0 = _sys_usw_dmps_db_get_internal_prop(lchip, GET_SUB_CHAN_ID_BY_DIR(dir_bmp), chan, sub_chan);
        if(CTC_E_NONE != ret0)
        {
            *sub_chan = DMPS_INVALID_VALUE_U16;
        }
    }
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

#define  ______SYS_USW_DMPS_DB_API______

int32
sys_usw_dmps_db_get_single_relative_id(uint8 lchip, uint8 src_db, uint16 src_id, uint8 dst_db, uint16* p_dst_id)
{
    int32 ret = 0;
    SYS_DMPS_DB_LOCK(lchip);

    ret = _sys_usw_dmps_db_get_single_relative_id(lchip, src_db, src_id, dst_db, p_dst_id);
    if(CTC_E_NONE != ret)
    {
        SYS_DMPS_DB_UNLOCK(lchip);
        return ret;
    }

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_relative_id(uint8 lchip, uint8 src_db, uint16 src_id, uint8 dst_db, 
                                      uint8* p_dst_num, uint16* arr_dst_id)
{
    int32 ret = 0;
    SYS_DMPS_DB_LOCK(lchip);

    ret = _sys_usw_dmps_db_get_relative_id(lchip, src_db, src_id, dst_db, p_dst_num, arr_dst_id);
    if(CTC_E_NONE != ret)
    {
        SYS_DMPS_DB_UNLOCK(lchip);
        return ret;
    }

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_dport_relative_id(uint8 lchip, uint16 dport, uint8 dst_db, uint16* p_dst_id)
{
    int32 ret = 0;
    SYS_DMPS_DB_LOCK(lchip);

    ret = _sys_usw_dmps_db_get_dport_relative_id(lchip, dport, dst_db, p_dst_id);
    if(CTC_E_NONE != ret)
    {
        SYS_DMPS_DB_UNLOCK(lchip);
        return ret;
    }

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

uint8
sys_usw_dmps_db_is_valid_id(uint8 lchip, uint8 db_type, uint16 db_id)
{
    uint8 is_valid = 0;

    SYS_DMPS_DB_LOCK(lchip);

    is_valid = _sys_usw_dmps_db_is_valid_id(lchip, db_type, db_id);

    SYS_DMPS_DB_UNLOCK(lchip);

    return is_valid;
}

uint8
sys_usw_dmps_db_is_lport_valid(uint8 lchip, uint16 lport)
{
    uint8  is_valid = 0;
    uint16 dport    = 0;

    SYS_DMPS_DB_LOCK(lchip);

    is_valid = (CTC_E_NONE == _sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport)) ? TRUE : FALSE;
    is_valid = (!is_valid) ? is_valid : (_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport) ? TRUE : FALSE);

    SYS_DMPS_DB_UNLOCK(lchip);

    return is_valid;
}

int32
sys_usw_dmps_db_is_usable_id(uint8 lchip, uint8 db_type, uint16 db_id)
{
    int32 ret = 0;
    SYS_DMPS_DB_LOCK(lchip);

    ret = _sys_usw_dmps_db_is_usable_id(lchip, db_type, db_id);
    if(CTC_E_NONE != ret)
    {
        SYS_DMPS_DB_UNLOCK(lchip);
        return ret;
    }

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_lport_2_dport(uint8 lchip, uint16 lport, uint16* p_dport)
{
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, p_dport));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_dport_2_lport(uint8 lchip, uint16 dport, uint16* p_lport)
{
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_dport_2_lport(lchip, dport, p_lport));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_core_id_by_dport(uint8 lchip, uint16 dport, uint8* core_id)
{
    uint8  dir_bmp   = 0;
    uint16 chan_id   = 0;

    SYS_DMPS_DB_LOCK(lchip);
    dir_bmp = CHAN_DIR_IS_RX(DMPS_DB_PORT(dport).xpipe_en) ? CHAN_DIR_RX : CHAN_DIR_TX;
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_dport_relative_id(lchip, dport, GET_CHAN_TYPE_BY_DIR(dir_bmp), &chan_id));
    *core_id = GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, core_id);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32 sys_usw_dmps_db_set_internal_prop(uint8 lchip, uint8 db_prop, uint32 id, void* p_value)
{
    int32 ret = 0;
    SYS_DMPS_DB_LOCK(lchip);

    ret = _sys_usw_dmps_db_set_internal_prop(lchip, db_prop, id, p_value);
    if(CTC_E_NONE != ret)
    {
        SYS_DMPS_DB_UNLOCK(lchip);
        return ret;
    }
    if (db_prop >= DMPS_DB_PORT_IDX && db_prop <= DMPS_DB_PORT_NP1_ABILITY1)
    {
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    }
    if (db_prop >= DMPS_DB_CHAN_CORE_ID && db_prop <= DMPS_DB_CHAN_PRIO)
    {
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN, 1);
    }
    if (db_prop >= DMPS_DB_CHAN_RX_CORE_ID && db_prop <= DMPS_DB_CHAN_RX_PRIO)
    {
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN_RX, 1);
    }
    if (db_prop >= DMPS_DB_MAC_SPEED && db_prop <= DMPS_DB_MAC_EN)
    {
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAC, 1);
    }
    if (db_prop >= DMPS_DB_PCS_IDX && db_prop <= DMPS_DB_PCS_RX_RST_EN)
    {
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PCS, 1);
    }
    if (db_prop >= DMPS_DB_PSD_PLL_SEL && db_prop <= DMPS_DB_PSD_IS_DYN)
    {
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD, 1);
    }
    if (db_prop >= DMPS_DB_LSD_LANE_ID && db_prop <= DMPS_DB_LSD_HSS_ID)
    {
        SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_LSD, 1);
    }
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32 sys_usw_dmps_db_get_internal_prop(uint8 lchip, uint8 db_prop, uint32 id, void* p_value)
{
    int32 ret = 0;
    SYS_DMPS_DB_LOCK(lchip);

    ret = _sys_usw_dmps_db_get_internal_prop(lchip, db_prop, id, p_value);
    if(CTC_E_NONE != ret)
    {
        SYS_DMPS_DB_UNLOCK(lchip);
        return ret;
    }

    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_alloc_chan_by_dir(uint8 lchip, uint32* p_chan_id, uint8 dir_bmp)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;
    SYS_DMPS_DB_LOCK(lchip);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = CHAN_DIR_IS_TX(dir_bmp) ? SYS_DMPS_DB_OPF_INDEX_CHAN : SYS_DMPS_DB_OPF_INDEX_CHAN_RX;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;

    ret = sys_usw_opf_alloc_offset(drv_vchip_get_pp_base(lchip), &opf, 1, p_chan_id);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_alloc_chan(uint8 lchip, uint32* p_chan_id)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;
    SYS_DMPS_DB_LOCK(lchip);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_CHAN;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;

    ret = sys_usw_opf_alloc_offset(drv_vchip_get_pp_base(lchip), &opf, 1, p_chan_id);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_CHAN_RX;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;

    ret = sys_usw_opf_alloc_offset(drv_vchip_get_pp_base(lchip), &opf, 1, p_chan_id);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_alloc_port(uint8 lchip, uint32* p_lport)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;
    SYS_DMPS_DB_LOCK(lchip);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_PORT;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;

    ret = sys_usw_opf_alloc_offset(drv_vchip_get_pp_base(lchip), &opf, 1, p_lport);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_assign_chan_by_dir(uint8 lchip, uint32 chan_id, uint8 dir_bmp)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;

    SYS_DMPS_DB_LOCK(lchip);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = CHAN_DIR_IS_TX(dir_bmp) ? SYS_DMPS_DB_OPF_INDEX_CHAN : SYS_DMPS_DB_OPF_INDEX_CHAN_RX;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;
    ret = sys_usw_opf_alloc_offset_from_position(drv_vchip_get_pp_base(lchip), &opf, 1, chan_id);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_assign_chan(uint8 lchip, uint32 chan_id)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;

    SYS_DMPS_DB_LOCK(lchip);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_CHAN;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;
    ret = sys_usw_opf_alloc_offset_from_position(drv_vchip_get_pp_base(lchip), &opf, 1, chan_id);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_CHAN_RX;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;
    ret = sys_usw_opf_alloc_offset_from_position(drv_vchip_get_pp_base(lchip), &opf, 1, chan_id);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_assign_port(uint8 lchip, uint32 lport)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;

    SYS_DMPS_DB_LOCK(lchip);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_PORT;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;
    ret = sys_usw_opf_alloc_offset_from_position(drv_vchip_get_pp_base(lchip), &opf, 1, lport);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_free_chan_by_dir(uint8 lchip, uint32 chan_id, uint8 dir_bmp)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;

    SYS_DMPS_DB_LOCK(lchip);

    opf.pool_index = CHAN_DIR_IS_TX(dir_bmp) ? SYS_DMPS_DB_OPF_INDEX_CHAN : SYS_DMPS_DB_OPF_INDEX_CHAN_RX;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;
    ret = sys_usw_opf_free_offset(drv_vchip_get_pp_base(lchip), &opf, 1, chan_id);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_free_chan(uint8 lchip, uint32 chan_id)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;

    SYS_DMPS_DB_LOCK(lchip);

    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_CHAN;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;
    ret = sys_usw_opf_free_offset(drv_vchip_get_pp_base(lchip), &opf, 1, chan_id);

    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_CHAN_RX;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;
    ret = sys_usw_opf_free_offset(drv_vchip_get_pp_base(lchip), &opf, 1, chan_id);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_free_port(uint8 lchip, uint32 p_lport)
{
    sys_usw_opf_t       opf;
    int32 ret = CTC_E_NONE;
    SYS_DMPS_DB_LOCK(lchip);

    sal_memset(&opf, 0, sizeof(sys_usw_opf_t));
    opf.pool_index = SYS_DMPS_DB_OPF_INDEX_PORT;
    opf.pool_type  = (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db;

    ret = sys_usw_opf_free_offset(drv_vchip_get_pp_base(lchip), &opf, 1, p_lport);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}


int32
sys_usw_dmps_db_get_misc_chan_info(uint8 lchip, uint8 misc_chan_type, sys_port_api_misc_chan_info_t* p_misc_info)
{
    int32 ret = CTC_E_NONE;
    SYS_DMPS_DB_LOCK(lchip);

    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_set_internal_port_info(uint8 lchip, sys_internal_port_info_t* p_port_info)
{
    CTC_PTR_VALID_CHECK(p_port_info);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_set_internal_port_info(lchip, p_port_info));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32 sys_usw_dmps_db_set_port_info(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info)
{
    CTC_PTR_VALID_CHECK(p_upt_info);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_set_port_info(lchip, p_upt_info));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32 sys_usw_dmps_db_get_port_info(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info)
{
    CTC_PTR_VALID_CHECK(p_upt_info);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_port_info(lchip, p_upt_info));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32 sys_usw_dmps_db_get_chan_info(uint8 lchip, sys_dmps_db_chan_info_t* chan_info, uint8 dir_bmp)
{
    CTC_PTR_VALID_CHECK(chan_info);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_chan_info(lchip, chan_info, dir_bmp));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_upt_info_init(uint8 lchip, sys_dmps_db_upt_info_t* p_upt_info)
{
    CTC_PTR_VALID_CHECK(p_upt_info);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_upt_info_init(lchip, p_upt_info));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_api_get_com_info(uint8 lchip, uint16 lport, uint8 index, sys_port_info_t* p_port_info)
{
    CTC_PTR_VALID_CHECK(p_port_info);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_api_get_com_info(lchip, lport, index, p_port_info));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_api_get_port_info(uint8 lchip, uint16 lport, sys_port_api_dmps_info_t* p_port_info)
{
    CTC_PTR_VALID_CHECK(p_port_info);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_api_get_port_info(lchip, lport, p_port_info));
    SYS_DMPS_DB_UNLOCK(lchip);
    return CTC_E_NONE;
}

/* p_value must be uint32* if is numerical */
int32
sys_usw_dmps_db_api_get_port_property(uint8 lchip, sys_dmps_port_info_t* port_info, sys_port_api_dmps_property_t port_prop, void *p_value)
{
    int32 ret = CTC_E_NONE;
    if (!MCHIP_DMPS_DB(lchip)->get_port_property)
    {
        return CTC_E_NOT_SUPPORT;
    }

    ret = MCHIP_DMPS_DB(lchip)->get_port_property(lchip, port_info, port_prop, p_value);

    return ret;
}

uint16
sys_usw_dmps_db_api_get_lport_with_chan(uint8 lchip, uint8 dir_bmp, uint16 chan_id)
{
    uint16 lport = 0;

    if (MCHIP_DMPS_DB(lchip)->get_lport_with_chan)
    {
        lport = MCHIP_DMPS_DB(lchip)->get_lport_with_chan(lchip, dir_bmp, chan_id);
    }

    return lport;
}

uint16
sys_usw_dmps_db_api_get_lport_with_subchan(uint8 lchip, uint8 dir_bmp, uint8 core, uint8 pp, uint8 dp, uint8 sub_chan)
{
    uint16 lport = 0;

    if (MCHIP_DMPS_DB(lchip)->get_lport_with_subchan)
    {
        ///TODO: need change para
        lport = MCHIP_DMPS_DB(lchip)->get_lport_with_subchan(lchip, dir_bmp, core, pp, dp, sub_chan);
    }

    return lport;
}

uint16
sys_usw_dmps_db_api_get_lport_with_mac(uint8 lchip, uint16 mac_id)
{
    uint16 lport = 0;

    if (MCHIP_DMPS_DB(lchip)->get_lport_with_mac)
    {
        lport = MCHIP_DMPS_DB(lchip)->get_lport_with_mac(lchip, mac_id);
    }

    return lport;
}

int32
sys_usw_dmps_db_api_get_sub_chan_by_chan(uint8 lchip, uint8 dir_bmp, uint16 chan, uint16* sub_chan, uint8* pp_id, uint8* dp_id)
{
    uint8 ret = CTC_E_NONE;

    if (MCHIP_DMPS_DB(lchip)->get_sub_chan_by_chan)
    {
        ret = MCHIP_DMPS_DB(lchip)->get_sub_chan_by_chan(lchip, dir_bmp, chan, sub_chan, pp_id, dp_id);
    }

    return ret;
}

int32
sys_usw_dmps_db_get_lport_by_serdes(uint8 lchip, uint16 psd, uint16 *lport)
{
    int32 ret = CTC_E_NONE;
    uint16 dport[DMPS_MAX_NUM_PER_MODULE] = {DMPS_INVALID_VALUE_U16};
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PSD, psd, 
        DMPS_DB_TYPE_PORT, NULL, dport));
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_dport_2_lport(lchip, dport[0], lport));
    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_get_lport_by_psd(uint8 lchip, uint16 psd, uint16 *lport)
{
    int32 ret = CTC_E_NONE;
    uint16 dport[DMPS_MAX_NUM_PER_MODULE] = {DMPS_INVALID_VALUE_U16};
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PSD, psd, 
        DMPS_DB_TYPE_PORT, NULL, dport));
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_dport_2_lport(lchip, dport[0], lport));
    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

int32
sys_usw_dmps_db_get_psd_by_dport(uint8 lchip, uint16 dport, uint16* psd, uint8* p_num)
{
    CTC_PTR_VALID_CHECK(psd);
    CTC_PTR_VALID_CHECK(p_num);

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, 
        DMPS_DB_TYPE_PSD, p_num, psd));

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_psd_by_lport(uint8 lchip, uint16 lport, uint16* psd, uint8* p_num)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(psd);
    CTC_PTR_VALID_CHECK(p_num);

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, 
        DMPS_DB_TYPE_PSD, p_num, psd));

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_lsd_by_lport(uint8 lchip, uint16 lport, uint16* lsd, uint8* p_num)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(lsd);
    CTC_PTR_VALID_CHECK(p_num);

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, 
        DMPS_DB_TYPE_LSD, p_num, lsd));

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_mac_en(uint8 lchip, uint16 lport, uint32* p_en)
{
    uint16 dport  = 0;
    uint16 mac_id = DMPS_INVALID_VALUE_U16;

    CTC_PTR_VALID_CHECK(p_en);

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    
    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_MAC, &mac_id));
    *p_en = DMPS_DB_MAC(mac_id).map.valid ? DMPS_DB_MAC(mac_id).en : 0;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_mac_en(uint8 lchip, uint16 lport, uint32 en)
{
    uint16 dport = 0;
    uint16 mac_id = DMPS_INVALID_VALUE_U16;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    
    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_MAC, &mac_id));
    DMPS_DB_MAC(mac_id).en = en ? 1 : 0;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAC, 1);
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

/*return sys_usw_dmps_fec_type_t*/
int32
sys_usw_dmps_db_get_fec_type(uint8 lchip, uint16 lport, uint8* p_fec_type)
{
    uint16 dport = 0;
    
    CTC_PTR_VALID_CHECK(p_fec_type);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    
    *p_fec_type = DMPS_DB_PORT(dport).fec_type;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_fec_type(uint8 lchip, uint16 lport, uint8 fec_type)
{
    uint16 dport = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).fec_type = fec_type;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_mac_id(uint8 lchip, uint16 lport, uint16* p_mac_id)
{
    uint16 dport = 0;

    CTC_PTR_VALID_CHECK(p_mac_id);

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_MAC, p_mac_id));

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_an_mode(uint8 lchip, uint16 lport, uint8* p_an_mode)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(p_an_mode);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    
    *p_an_mode = DMPS_DB_PORT(dport).an_mode;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_an_mode(uint8 lchip, uint16 lport, uint8 an_mode)
{
    uint16 dport  = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).an_mode = an_mode;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_an_fec(uint8 lchip, uint16 lport, uint32* p_an_fec)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(p_an_fec);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);

    *p_an_fec = DMPS_DB_PORT(dport).an_fec;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_an_fec(uint8 lchip, uint16 lport, uint32 an_fec)
{
    uint16 dport  = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    
    DMPS_DB_PORT(dport).an_fec = 0;
    if (CTC_PORT_FEC_TYPE_NONE != an_fec)
    {
        if (an_fec & (1 << CTC_PORT_FEC_TYPE_RS))
        {
            DMPS_DB_PORT(dport).an_fec |= (1 << CTC_PORT_FEC_TYPE_RS);
        }
        if (an_fec & (1 << CTC_PORT_FEC_TYPE_BASER))
        {
            DMPS_DB_PORT(dport).an_fec |= (1 << CTC_PORT_FEC_TYPE_BASER);
        }
    }
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_speed_mode(uint8 lchip, uint16 lport, uint8* p_speed_mode)
{
    uint16 dport  = 0;
    uint16 chan_id = 0;
    
    CTC_PTR_VALID_CHECK(p_speed_mode);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    
    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_CHAN, &chan_id));

    *p_speed_mode = DMPS_DB_CHAN(chan_id).speed_mode;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_speed_mode(uint8 lchip, uint16 lport, uint8 speed_mode)
{
    uint16 dport  = 0;
    uint16 chan_id = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    
    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_dport_relative_id(lchip, dport, DMPS_DB_TYPE_CHAN, &chan_id));

    DMPS_DB_CHAN(chan_id).speed_mode = speed_mode;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_ifmode(uint8 lchip, uint16 lport, uint8* p_mode)
{
    uint16 dport  = 0;
    
    CTC_PTR_VALID_CHECK(p_mode);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PORT);

    *p_mode = DMPS_DB_PORT(dport).if_mode;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_ifmode_by_psd(uint8 lchip, uint16 psd, uint8* p_mode)
{
    uint16 dport[8]  = {DMPS_INVALID_VALUE_U16};
    
    CTC_PTR_VALID_CHECK(p_mode);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PSD, psd, 
        DMPS_DB_TYPE_PORT, NULL, dport));

    if (DMPS_INVALID_VALUE_U16 == dport[0])
    {
        SYS_DMPS_DB_UNLOCK(lchip);
        return CTC_E_INVALID_PORT;
    }

    *p_mode = DMPS_DB_PORT(dport[0]).if_mode;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_ifmode(uint8 lchip, uint16 lport, uint8 mode)
{
    uint16 dport  = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).if_mode = mode;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_xpipe_en(uint8 lchip, uint16 lport, uint32* p_en)
{
    uint16 dport = 0;

    CTC_PTR_VALID_CHECK(p_en);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    *p_en = DMPS_DB_PORT(dport).xpipe_en;
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_xpipe_en(uint8 lchip, uint16 lport, uint32 en)
{
    uint16 dport = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    
    DMPS_DB_PORT(dport).xpipe_en = en;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_serdes_speed(uint8 lchip, uint16 psd, uint32* p_speed)
{
    CTC_PTR_VALID_CHECK(p_speed);
    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    *p_speed = DMPS_DB_PSD(psd).serdes_speed;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_serdes_speed(uint8 lchip, uint16 psd, uint32 speed)
{
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);
    
    DMPS_DB_PSD(psd).serdes_speed = speed;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_serdes_ocs(uint8 lchip, uint16 psd, uint8* p_ocs)
{
    CTC_PTR_VALID_CHECK(p_ocs);
    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    *p_ocs = DMPS_DB_PSD(psd).ocs;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_serdes_ocs(uint8 lchip, uint16 psd, uint8 ocs)
{
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PSD(psd).ocs = ocs;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD, 1);
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_port_type(uint8 lchip, uint16 lport, uint8* p_port_type)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(p_port_type);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);

    *p_port_type = DMPS_DB_PORT(dport).port_type;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_port_type(uint8 lchip, uint16 lport, uint8 port_type)
{
    uint16 dport  = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).port_type = port_type;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_pcs_idx(uint8 lchip, uint16 pcs_id, uint8* p_pcs_idx)
{
    CTC_PTR_VALID_CHECK(p_pcs_idx);
    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, pcs_id), 
        CTC_E_INVALID_PARAM);

    *p_pcs_idx = DMPS_DB_PCS(pcs_id).pcs_idx;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_psd_polarity(uint8 lchip, uint16 psd, uint8* p_tx_pol, uint8* p_rx_pol)
{    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    SYS_USW_VALID_PTR_WRITE(p_tx_pol, DMPS_DB_PSD(psd).tx_polarity);
    SYS_USW_VALID_PTR_WRITE(p_rx_pol, DMPS_DB_PSD(psd).rx_polarity);
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_psd_polarity(uint8 lchip, uint16 psd, uint8 dir, uint8 pol)
{    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    if(DMPS_RX == dir)
    {
        DMPS_DB_PSD(psd).rx_polarity = pol;
    }
    else
    {
        DMPS_DB_PSD(psd).tx_polarity = pol;
    }
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_psd_data_width(uint8 lchip, uint16 psd, uint8* p_data_width)
{    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    SYS_USW_VALID_PTR_WRITE(p_data_width, DMPS_DB_PSD(psd).bit_width);
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_psd_data_width(uint8 lchip, uint16 psd, uint8 data_width)
{    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PSD(psd).bit_width = data_width;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD, 1);
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_psd_rate_div(uint8 lchip, uint16 psd, uint8* p_rate_div)
{    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    SYS_USW_VALID_PTR_WRITE(p_rate_div, DMPS_DB_PSD(psd).rate_div);
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_psd_rate_div(uint8 lchip, uint16 psd, uint8 rate_div)
{    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, psd), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PSD(psd).rate_div = rate_div;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD, 1);
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_pcs_idx(uint8 lchip, uint16 pcs_id, uint8 pcs_idx)
{
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, pcs_id), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PCS(pcs_id).pcs_idx = pcs_idx;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PCS, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_cl73_en(uint8 lchip, uint16 lport, uint32* p_an_en)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(p_an_en);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK((DMPS_DB_PORT(dport).port_type != SYS_DMPS_NETWORK_PORT)  && 
        (!SYS_USW_IS_CPUMAC_PORT(DMPS_DB_PORT(dport).port_type)), CTC_E_INVALID_PARAM);

    *p_an_en = DMPS_DB_PORT(dport).an_en;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_cl73_en(uint8 lchip, uint16 lport, uint32 an_en)
{
    uint16 dport  = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK((DMPS_DB_PORT(dport).port_type != SYS_DMPS_NETWORK_PORT)  && 
        (!SYS_USW_IS_CPUMAC_PORT(DMPS_DB_PORT(dport).port_type)), CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).an_en = an_en;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_link_fsm(uint8 lchip, uint16 lport, uint32* p_link_fsm)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(p_link_fsm);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK((DMPS_DB_PORT(dport).port_type != SYS_DMPS_NETWORK_PORT)  && 
        (!SYS_USW_IS_CPUMAC_PORT(DMPS_DB_PORT(dport).port_type)), CTC_E_INVALID_PARAM);

    *p_link_fsm = DMPS_DB_PORT(dport).link_fsm;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_link_fsm(uint8 lchip, uint16 lport, uint32 link_fsm)
{
    uint16 dport  = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK((DMPS_DB_PORT(dport).port_type != SYS_DMPS_NETWORK_PORT)  && 
        (!SYS_USW_IS_CPUMAC_PORT(DMPS_DB_PORT(dport).port_type)), CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).link_fsm = link_fsm;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_link_mode(uint8 lchip, uint16 lport, uint32* p_link_mode)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(p_link_mode);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK((DMPS_DB_PORT(dport).port_type != SYS_DMPS_NETWORK_PORT)  && 
        (!SYS_USW_IS_CPUMAC_PORT(DMPS_DB_PORT(dport).port_type)), CTC_E_INVALID_PARAM);

    *p_link_mode = DMPS_DB_PORT(dport).link_mode;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_link_mode_by_dport(uint8 lchip, uint16 dport, uint32* p_link_mode)
{
    CTC_PTR_VALID_CHECK(p_link_mode);
    
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK((DMPS_DB_PORT(dport).port_type != SYS_DMPS_NETWORK_PORT)  && 
        (!SYS_USW_IS_CPUMAC_PORT(DMPS_DB_PORT(dport).port_type)), CTC_E_INVALID_PARAM);

    *p_link_mode = DMPS_DB_PORT(dport).link_mode;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_link_mode(uint8 lchip, uint16 lport, uint32 link_mode)
{
    uint16 dport  = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK((DMPS_DB_PORT(dport).port_type != SYS_DMPS_NETWORK_PORT)  && 
        (!SYS_USW_IS_CPUMAC_PORT(DMPS_DB_PORT(dport).port_type)), CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).link_mode = link_mode;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_link_mode_by_dport(uint8 lchip, uint16 dport, uint32 link_mode)
{
    SYS_DMPS_DB_LOCK(lchip);

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK((DMPS_DB_PORT(dport).port_type != SYS_DMPS_NETWORK_PORT)  && 
        (!SYS_USW_IS_CPUMAC_PORT(DMPS_DB_PORT(dport).port_type)), CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).link_mode = link_mode;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_an_en(uint8 lchip, uint16 lport, uint32* p_an_en)
{
    uint16 dport  = 0;

    CTC_PTR_VALID_CHECK(p_an_en);
    
    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    
    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);
    
    *p_an_en = DMPS_DB_PORT(dport).an_en;
    
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_an_en(uint8 lchip, uint16 lport, uint32 an_en)
{
    uint16 dport  = 0;

    SYS_DMPS_DB_LOCK(lchip);

    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));

    SYS_CONDITION_RETURN_DMPS_DB_UNLOCK(FALSE == _sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, dport), 
        CTC_E_INVALID_PARAM);

    DMPS_DB_PORT(dport).an_en = an_en;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_mac_group_valid(uint8 lchip, uint8 core_id, uint32* p_mac_group_valid)
{
    SYS_CONDITION_RETURN(core_id >= DMPS_MAX_CORE_NUM, CTC_E_INVALID_PARAM);
    CTC_PTR_VALID_CHECK(p_mac_group_valid);
    SYS_DMPS_DB_LOCK(lchip);
    *p_mac_group_valid = p_usw_dmps_db_master[lchip]->mac_group_is_valid[core_id];
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_mac_group_valid(uint8 lchip, uint8 core_id, uint32 mac_group_valid)
{
    SYS_CONDITION_RETURN(core_id >= DMPS_MAX_CORE_NUM, CTC_E_INVALID_PARAM);
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->mac_group_is_valid[core_id] = mac_group_valid;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_chan_by_info(uint8 lchip, uint8 p_core_id, uint8 p_pp_id, uint8 p_dp_id, uint16 index_in_dp, uint16* p_chan_id)
{
    uint8  core_id = 0;
    uint8  pp_id   = 0;
    uint8  dp_id   = 0;
    uint16 chan_id = 0;
    uint16 mac_cli = 0;
    int32 ret = 0;
    sys_dmps_db_upt_info_t port_info = {0};

    CTC_PTR_VALID_CHECK(p_chan_id);
    SYS_DMPS_DB_LOCK(lchip);
    for (chan_id = 0; chan_id < SYS_USW_MAX_PORT_NUM_PER_CHIP; chan_id++)
    {
        (void) _sys_usw_dmps_db_upt_info_init(lchip, &port_info);
        DMPS_DB_SET_MAP_INFO(port_info, DMPS_DB_CHAN_ID,  chan_id);
        DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_CORE_ID);
        DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_PP_ID);
        DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_DP_ID);
        DMPS_DB_SET_PROPERTY_UPDATE(port_info, DMPS_DB_CHAN_MAC_CLIENT_ID);
        CTC_ERROR_GOTO(_sys_usw_dmps_db_get_port_info(lchip, &port_info),ret,proc);
        DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_CORE_ID,        core_id);
        DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_PP_ID,          pp_id);
        DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_DP_ID,          dp_id);
        DMPS_DB_GET_PROPERTY_INFO(port_info, DMPS_DB_CHAN_MAC_CLIENT_ID,  mac_cli);

        if ((core_id == p_core_id) && (pp_id == p_pp_id) && (dp_id == p_dp_id) && (mac_cli == index_in_dp))
        {
            *p_chan_id = chan_id;
            ret = CTC_E_NONE;
            goto proc;
        }
    }
    *p_chan_id = DMPS_INVALID_VALUE_U16;
proc:
    SYS_DMPS_DB_UNLOCK(lchip);
    return ret;
}

void
sys_usw_dmps_db_print_ext_lport_map(uint8 lchip, uint32 sign)
{
    uint16 lport;
    sal_printf("\n\n\nsign %u\n", sign);
    sal_printf("bpe_full_mode %u\n", p_usw_dmps_db_master[lchip]->bpe_full_mode);
    for(lport = 0; lport < DMPS_MAX_PORT_NUM; lport++)
    {
        sal_printf("lport %u, dport %u\n", lport, p_usw_dmps_db_master[lchip]->ext_lport_map[lport]);
    }
}

uint8
sys_usw_dmps_db_is_exist_bpefull_port(uint8 lchip)
{
    uint16 lport;
    uint8  is_exist = FALSE;
    uint8  bpe_full = 0;
    
    SYS_DMPS_DB_LOCK(lchip);
    
    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_bpe_full_mode(lchip, &bpe_full));
    if(0 == bpe_full)
    {
        SYS_DMPS_DB_UNLOCK(lchip);
        return is_exist;
    }
    
    for(lport = 0; lport < SYS_INTERNAL_PORT_END; lport++)
    {
        if(p_usw_dmps_db_master[lchip]->ext_lport_map[lport] != DMPS_INVALID_VALUE_U16)
        {
            is_exist = TRUE;
            break;
        }
    }
    
    SYS_DMPS_DB_UNLOCK(lchip);

    return is_exist;
}

int32
sys_usw_dmps_db_set_ext_lport_map(uint8 lchip, uint16 lport, uint16 dport)
{
    SYS_CONDITION_RETURN(lport >= DMPS_MAX_PORT_NUM, CTC_E_INVALID_PARAM);
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->ext_lport_map[lport] = dport;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_bpe_full_mode(uint8 lchip, uint8* p_bpe_full)
{
    CTC_PTR_VALID_CHECK(p_bpe_full);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_bpe_full_mode(lchip, p_bpe_full));
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_bpe_full_mode(uint8 lchip, uint8 bpe_full_mode)
{
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->bpe_full_mode = bpe_full_mode;
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_serdes_scale(uint8 lchip, uint8* p_serdes_scale)
{
    CTC_PTR_VALID_CHECK(p_serdes_scale);
    SYS_DMPS_DB_LOCK(lchip);
    *p_serdes_scale = (uint8) p_usw_dmps_db_master[lchip]->serdes_scale;
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_serdes_scale(uint8 lchip, uint8 p_serdes_scale)
{
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->serdes_scale = p_serdes_scale % SYS_DMPS_DB_SERDES_SCALE_MAX;
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32 
sys_usw_dmps_db_set_xpipe_alloc(uint8 lchip, uint8 xpipe_alloc)
{
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->xpipe_alloc = xpipe_alloc;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER, 1);
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32 
sys_usw_dmps_db_get_xpipe_alloc(uint8 lchip, uint8* xpipe_alloc)
{
    CTC_PTR_VALID_CHECK(xpipe_alloc);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DMPS_DB_UNLOCK(_sys_usw_dmps_db_get_xpipe_alloc(lchip, xpipe_alloc));
    SYS_DMPS_DB_UNLOCK(lchip);
   
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_chan2lsd(uint8 lchip, uint8 core_id, uint16 chan_idx, 
                                      uint8* p_occupy_flag, uint16* p_lsd, uint16* p_dport)
{
    SYS_CONDITION_RETURN((core_id >= DMPS_MAX_CORE_NUM) || (chan_idx >= DMPS_NW_CPU_NUM_PER_CORE), 
        CTC_E_INVALID_PARAM);

    SYS_DMPS_DB_LOCK(lchip);

    SYS_USW_VALID_PTR_WRITE(p_occupy_flag, 
        p_usw_dmps_db_master[lchip]->chan_2_logic_serdes[core_id][chan_idx].occupy_flag);
    SYS_USW_VALID_PTR_WRITE(p_lsd, 
        p_usw_dmps_db_master[lchip]->chan_2_logic_serdes[core_id][chan_idx].logic_serdes_id);
    SYS_USW_VALID_PTR_WRITE(p_dport, 
        p_usw_dmps_db_master[lchip]->chan_2_logic_serdes[core_id][chan_idx].dport);

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_chan2lsd(uint8 lchip, uint8 core_id, uint16 chan_idx, 
                                      uint8 occupy_flag, uint16 lsd, uint16 dport)
{
    SYS_CONDITION_RETURN((core_id >= DMPS_MAX_CORE_NUM) || (chan_idx >= DMPS_NW_CPU_NUM_PER_CORE), 
        CTC_E_INVALID_PARAM);

    SYS_DMPS_DB_LOCK(lchip);

    p_usw_dmps_db_master[lchip]->chan_2_logic_serdes[core_id][chan_idx].logic_serdes_id = lsd;
    p_usw_dmps_db_master[lchip]->chan_2_logic_serdes[core_id][chan_idx].occupy_flag     = occupy_flag;
    p_usw_dmps_db_master[lchip]->chan_2_logic_serdes[core_id][chan_idx].dport           = dport;

    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER, 1);

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_core_pll(uint8 lchip, uint16* p_core_pll, uint8 core_type)
{
    CTC_PTR_VALID_CHECK(p_core_pll);
    SYS_DMPS_DB_LOCK(lchip);
    if (1 == core_type) /* clock dp */
    {
        *p_core_pll = (uint16) p_usw_dmps_db_master[lchip]->core_pll;
    }
    else if (0 == core_type) /* clock pp */
    {
         *p_core_pll = (1350 == p_usw_dmps_db_master[lchip]->core_pll) ? 1400 : 
            ((900 == p_usw_dmps_db_master[lchip]->core_pll) ? 1000 : 600);
    }
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_core_pll(uint8 lchip, uint16 core_pll)
{
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->core_pll = core_pll;
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_cpumac_dport(uint8 lchip, uint8 port_idx, uint16* p_dport)
{
    SYS_CONDITION_RETURN(port_idx >= DMPS_MAX_NUM_CPUMAC_MAP, CTC_E_INVALID_PARAM);
    CTC_PTR_VALID_CHECK(p_dport);
    SYS_DMPS_DB_LOCK(lchip);
    *p_dport = p_usw_dmps_db_master[lchip]->cpumac_dport[port_idx];
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_cpumac_dport(uint8 lchip, uint8 port_idx, uint16 dport)
{
    SYS_CONDITION_RETURN(port_idx >= DMPS_MAX_NUM_CPUMAC_MAP, CTC_E_INVALID_PARAM);
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->cpumac_dport[port_idx] = dport;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_cpumac_map(uint8 lchip, uint8 port_idx, sys_dmps_db_cpumac_map_t* p_map)
{
    SYS_CONDITION_RETURN(port_idx >= DMPS_MAX_NUM_CPUMAC_MAP, CTC_E_INVALID_PARAM);
    CTC_PTR_VALID_CHECK(p_map);
    SYS_DMPS_DB_LOCK(lchip);
    *p_map = p_usw_dmps_db_master[lchip]->cpumac_map[port_idx];
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_cpumac_map(uint8 lchip, uint8 port_idx, sys_dmps_db_cpumac_map_t* p_map)
{
    SYS_CONDITION_RETURN(port_idx >= DMPS_MAX_NUM_CPUMAC_MAP, CTC_E_INVALID_PARAM);
    CTC_PTR_VALID_CHECK(p_map);
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->cpumac_map[port_idx] = *p_map;
    SYS_USW_REGISTER_WB_SYNC_EN(lchip, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER, 1);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_cpumac_get_lport_info_by_inner_idx(uint8 lchip, uint8 inner_idx, uint16* lport, uint8 *is_network)
{
    SYS_DMPS_DB_LOCK(lchip);
    SYS_USW_VALID_PTR_WRITE(lport,      p_usw_dmps_db_master[lchip]->cpumac_map[inner_idx].lport);
    SYS_USW_VALID_PTR_WRITE(is_network, p_usw_dmps_db_master[lchip]->cpumac_map[inner_idx].is_network);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_core_pp_dp_txqm_by_chan(uint8 lchip, uint16 chan_id, 
                                               uint8* p_core_id, uint8* p_pp_id, uint8* p_dp_id, uint8* p_txqm_id, uint8 dir_bmp)
{
    SYS_DMPS_DB_LOCK(lchip);
    SYS_USW_VALID_PTR_WRITE(p_core_id, GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, core_id));
    SYS_USW_VALID_PTR_WRITE(p_pp_id,   GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, pp_id));
    SYS_USW_VALID_PTR_WRITE(p_dp_id,   GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, dp_id));
    SYS_USW_VALID_PTR_WRITE(p_txqm_id, GET_CHAN_DB_BY_DIR(dir_bmp, chan_id, txqm_id));
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_interface_mode(uint8 lchip, uint16 lport, ctc_port_if_mode_t* if_mode)
{
    uint16 dport   = 0;
    uint16 chan_id = 0;

    CTC_PTR_VALID_CHECK(if_mode);
    SYS_DMPS_DB_LOCK(lchip);
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_lport_2_dport(lchip, lport, &dport));
    CTC_ERROR_RETURN_DB_UNLOCK(_sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_PORT, dport, DMPS_DB_TYPE_CHAN, NULL, &chan_id));
    if_mode->interface_type = DMPS_DB_PORT(dport).if_type;
    if_mode->speed          = DMPS_DB_CHAN(chan_id).speed_mode;
    SYS_DMPS_DB_UNLOCK(lchip);
    
    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_glbcfg_from_db(uint8 lchip, ctc_datapath_global_cfg_t* p_glbcfg)
{
    uint16 lsd;
    uint16 temp_serdes_id = 0;
    uint16 psd[DMPS_MAX_NUM_PER_MODULE]   = {0};
    uint16 dport[DMPS_MAX_NUM_PER_MODULE] = {0};
    ctc_datapath_serdes_prop_t* p_serdes  = NULL;
    int32 ret = CTC_E_NONE;

    CTC_PTR_VALID_CHECK(p_glbcfg);
    sal_memset(p_glbcfg, 0 ,sizeof(ctc_datapath_global_cfg_t));
    p_serdes = p_glbcfg->serdes;

    SYS_DMPS_DB_LOCK(lchip);

    p_glbcfg->core_frequency_a      = (uint16) p_usw_dmps_db_master[lchip]->core_pll;
    ///TODO: cpumac nw switch change to 4
    p_glbcfg->cpumac_dp0_network_en = p_usw_dmps_db_master[lchip]->cpumac_map[0].is_network;
    p_glbcfg->cpumac_dp1_network_en = p_usw_dmps_db_master[lchip]->cpumac_map[1].is_network;
    p_glbcfg->bpe_full_mode         = (uint8) p_usw_dmps_db_master[lchip]->bpe_full_mode;
    p_glbcfg->mode                  = p_usw_dmps_db_master[lchip]->serdes_scale % 10;

    for(lsd = 0; lsd < CTC_DATAPATH_SERDES_NUM; lsd++)
    {
        if((CTC_E_NONE != _sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_LSD, lsd, DMPS_DB_TYPE_PORT, NULL, dport)) || 
           (CTC_E_NONE != _sys_usw_dmps_db_get_relative_id(lchip, DMPS_DB_TYPE_LSD, lsd, DMPS_DB_TYPE_PSD, NULL, psd)))
        {
            p_serdes[lsd].mode               = 3;
            p_serdes[lsd].is_dynamic         = 0;
            p_serdes[lsd].rx_polarity        = 0;
            p_serdes[lsd].tx_polarity        = 0;
            p_serdes[lsd].physical_serdes_id = SYS_DMPS_INVALID_U16;
            p_serdes[lsd].logical_serdes_id  = lsd;
        }
        else
        {
            p_serdes[lsd].mode               = DMPS_DB_PORT(dport[0]).if_mode;
            p_serdes[lsd].is_dynamic         = DMPS_DB_PSD(psd[0]).is_dyn;
            p_serdes[lsd].rx_polarity        = DMPS_DB_PSD(psd[0]).rx_polarity;
            p_serdes[lsd].tx_polarity        = DMPS_DB_PSD(psd[0]).tx_polarity;
            if (MCHIP_DMPS(lchip)->psd_to_serdes)
            {
                ret = MCHIP_DMPS(lchip)->psd_to_serdes(lchip, psd[0], &temp_serdes_id);
                if (CTC_E_NONE != ret)
                {
                    SYS_DMPS_DB_UNLOCK(lchip);
                    return ret;
                }
            }
            else
            {
                temp_serdes_id = psd[0];
            }
            p_serdes[lsd].physical_serdes_id = temp_serdes_id;
            p_serdes[lsd].logical_serdes_id  = lsd;
        }
    }

    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_get_msg_handle(uint8 lchip, sys_dmps_db_msg_handle_t **pp_handle)
{
    CTC_PTR_VALID_CHECK(pp_handle);
    
    SYS_DMPS_DB_LOCK(lchip);
    *pp_handle = (sys_dmps_db_msg_handle_t* )(&p_usw_dmps_db_master[lchip]->dmps_msg_handle);
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_msg_handle(uint8 lchip, sys_dmps_db_msg_handle_t *p_handle)
{
    CTC_PTR_VALID_CHECK(p_handle);
    
    SYS_DMPS_DB_LOCK(lchip);
    sal_memcpy(&p_usw_dmps_db_master[lchip]->dmps_msg_handle, p_handle, sizeof(sys_dmps_db_msg_handle_t));
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_set_msg_registers_tab(uint8 lchip, uint32 msg_type, uint8 priority, uint8 data_size, void* recv_cb)
{
    if (msg_type >= SYS_DMPS_MSG_CODE_MAX)
    {
        SYS_MAC_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, " %% INVALID PARAM. | %s()@%d\n", __FUNCTION__, __LINE__); 
        return CTC_E_INVALID_PARAM;
    }
        
    SYS_DMPS_DB_LOCK(lchip);
    p_usw_dmps_db_master[lchip]->dmps_msg_handle.registers[msg_type].priority      = priority;
    p_usw_dmps_db_master[lchip]->dmps_msg_handle.registers[msg_type].rps_data_size = data_size;
    p_usw_dmps_db_master[lchip]->dmps_msg_handle.registers[msg_type].recv_cb       = recv_cb;
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_init(uint8 lchip)
{
    int32 ret = CTC_E_NONE;

    if (NULL != p_usw_dmps_db_master[lchip])
    {
        return CTC_E_NONE;
    }
    SYS_VCHIP_MASTER_INIT(lchip, p_usw_dmps_db_master, CTC_FEATURE_DATAPATH);

    p_usw_dmps_db_master[lchip] = (sys_dmps_db_master_t*)mem_malloc(MEM_DMPS_MODULE, sizeof(sys_dmps_db_master_t));
    if (NULL == p_usw_dmps_db_master[lchip])
    {
        SYS_DMPS_DB_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, " No memory for master \n");
        return CTC_E_NO_MEMORY;
    }
    sal_memset(p_usw_dmps_db_master[lchip], 0, sizeof(sys_dmps_db_master_t));
    sal_memset(p_usw_dmps_db_master[lchip]->cpumac_map, 0xff, DMPS_MAX_NUM_CPUMAC_MAP * sizeof(sys_dmps_db_cpumac_map_t));

    ret = sal_mutex_create(&(p_usw_dmps_db_master[lchip]->mutex));
    if (ret || !(p_usw_dmps_db_master[lchip]->mutex))
    {
        SYS_DMPS_DB_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, " Create mutex fail\n");
        goto roll_back_0;
    }

    p_usw_dmps_db_master[lchip]->dmps_db = (sys_dmps_db_t*)mem_malloc(MEM_DMPS_MODULE, sizeof(sys_dmps_db_t));
    if (!p_usw_dmps_db_master[lchip]->dmps_db)
    {
        SYS_DMPS_DB_DBG_OUT(CTC_DEBUG_LEVEL_ERROR, " No memory \n");
        goto roll_back_2;
    }
    sal_memset(p_usw_dmps_db_master[lchip]->dmps_db, 0, sizeof(sys_dmps_db_t));

    sal_memset(p_usw_dmps_db_master[lchip]->ext_lport_map, DMPS_INVALID_VALUE_U8, DMPS_MAX_PORT_NUM * sizeof(uint16));
    p_usw_dmps_db_master[lchip]->serdes_scale = SYS_DMPS_DB_SERDES_SCALE_MAX;

    CTC_ERROR_GOTO(_sys_usw_dmps_db_init(lchip), ret, roll_back_3);

    CTC_ERROR_GOTO(_sys_usw_dmps_db_init_opf(lchip), ret, roll_back_3);
    
    //CTC_ERROR_GOTO(sys_usw_dump_db_register_cb(lchip, CTC_FEATURE_DATAPATH, sys_usw_dmps_db_dump), ret, roll_back_3);

    if (!SYS_USW_DMPS_IS_OLD_DB(lchip))
    {
        if (CTC_WB_ENABLE(lchip) && CTC_WB_STATUS(lchip) == CTC_WB_STATUS_RELOADING)
        {
            CTC_ERROR_GOTO(sys_usw_dmps_wb_restore_master(lchip), ret, roll_back_3);
        }
        if (CTC_WB_ENABLE(lchip))
        {
            (void) sys_usw_dmps_wb_init(lchip);
        }
    }

    return CTC_E_NONE;
    
roll_back_3:
    mem_free(p_usw_dmps_db_master[lchip]->dmps_db);
roll_back_2:
    sal_mutex_destroy(p_usw_dmps_db_master[lchip]->mutex);
    p_usw_dmps_db_master[lchip]->mutex = NULL;
roll_back_0:
    mem_free(p_usw_dmps_db_master[lchip]);
    p_usw_dmps_db_master[lchip] = 0;

    return ret;
}

int32
sys_usw_dmps_db_deinit(uint8 lchip)
{
    sys_dmps_mapping_set_t* map_node = NULL;
    LCHIP_CHECK(lchip);
    if (!SYS_USW_DMPS_IS_OLD_DB(lchip))
    {
        sys_usw_dump_db_register_cb(lchip, CTC_FEATURE_DATAPATH, NULL);
        sys_usw_wb_sync_register_cb(lchip, CTC_FEATURE_DATAPATH, 0, NULL);
    }
    if (NULL == p_usw_dmps_db_master[lchip])
    {
        return CTC_E_NONE;
    }
    SYS_VCHIP_MASTER_DEINIT(lchip, p_usw_dmps_db_master, CTC_FEATURE_DATAPATH);

    if (0 != p_usw_dmps_db_master[lchip]->opf_type_dmps_db)
    {
        sys_usw_opf_deinit(lchip, (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db);
    }

    /* free all map_node */
    while (p_usw_dmps_db_master[lchip]->map_node_list.count > 0)
    {
        map_node = _ctc_container_of(p_usw_dmps_db_master[lchip]->map_node_list.head, sys_dmps_mapping_set_t, head);
        ctc_slist_delete_node(&(p_usw_dmps_db_master[lchip]->map_node_list), &(map_node->head));

        sal_memset(map_node, 0, sizeof(sys_dmps_mapping_set_t));

        mem_free(map_node);
    }

    if (NULL != p_usw_dmps_db_master[lchip]->dmps_db)
    {
        mem_free(p_usw_dmps_db_master[lchip]->dmps_db);
    }

    if (p_usw_dmps_db_master[lchip]->mutex)
    {
        sal_mutex_destroy(p_usw_dmps_db_master[lchip]->mutex);
        p_usw_dmps_db_master[lchip]->mutex = NULL;
    }

    mem_free(p_usw_dmps_db_master[lchip]);
    p_usw_dmps_db_master[lchip] = 0;

    return CTC_E_NONE;
}

#define ______SYS_USW_DMPS_DB_DUMP______

int32
_sys_usw_dmps_db_dump_port_db_item(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t fp)
{
    if(title_flag)
    {
        SYS_DUMP_DB_LOG(fp, "%-5s ",  "id");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "port_idx");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "port_type");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "if_type");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "if_mode");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "fec_type");
        SYS_DUMP_DB_LOG(fp, "%-7s ",  "an_fec");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "mdio_map");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "phy_map");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "devno_map");
        SYS_DUMP_DB_LOG(fp, "%-6s ",  "an_en");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "cl73_sta");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "intr_en");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "link_sta");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "unidir_en");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "rx_rst_h");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "ctle_run");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "xpipe_en");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "is_an_st");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "base_ab0");
        SYS_DUMP_DB_LOG(fp, "%-9s ",  "base_ab1");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "np0_ab0");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "np0_ab1");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "np1_ab0");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "np1_ab1");
        SYS_DUMP_DB_LOG(fp, "%-8s ",  "lk_mode");
        SYS_DUMP_DB_LOG(fp, "%-7s ",  "lk_fsm");
        
        SYS_DUMP_DB_LOG(fp, "\n");
    }

    if (!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PORT, item_id))
    {
        return CTC_E_NONE;
    }
    
    SYS_DUMP_DB_LOG(fp, "%-5u ",  item_id);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).port_idx);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PORT(item_id).port_type);
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).if_type);
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).if_mode);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).fec_type);
    SYS_DUMP_DB_LOG(fp, "%-7u ",  DMPS_DB_PORT(item_id).an_fec);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).mdio_map);
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).phy_map);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PORT(item_id).devno_map);
    SYS_DUMP_DB_LOG(fp, "%-6u ",  DMPS_DB_PORT(item_id).an_en);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).old_cl73_status);
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).link_intr_en);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).link_status);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PORT(item_id).unidir_en);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).rx_rst_hold);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).is_ctle_running);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).xpipe_en);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).is_an_first);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).an_ability.base_ability0);
    SYS_DUMP_DB_LOG(fp, "%-9u ",  DMPS_DB_PORT(item_id).an_ability.base_ability1);
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).an_ability.np0_ability0);
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).an_ability.np0_ability1);
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).an_ability.np1_ability0);
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).an_ability.np1_ability1); 
    SYS_DUMP_DB_LOG(fp, "%-8u ",  DMPS_DB_PORT(item_id).link_mode);
    SYS_DUMP_DB_LOG(fp, "%-7u ",  DMPS_DB_PORT(item_id).link_fsm);
    
    SYS_DUMP_DB_LOG(fp, "\n");

    return CTC_E_NONE;
}


int32
_sys_usw_dmps_db_dump_mac_db_item(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t fp)
{
    if(title_flag)
    {
        SYS_DUMP_DB_LOG(fp, "%-5s ", "id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "en");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "mac_speed");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "mac_group");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "mac_idx"); 
        
        SYS_DUMP_DB_LOG(fp, "\n");
    }

    if (!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_MAC, item_id))
    {
        return CTC_E_NONE;
    }

    SYS_DUMP_DB_LOG(fp, "%-5u ", item_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_MAC(item_id).en);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_MAC(item_id).mac_speed);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_MAC(item_id).mac_group_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_MAC(item_id).mac_idx);
    
    SYS_DUMP_DB_LOG(fp, "\n");

    return CTC_E_NONE;
}

#define  ______SYS_USW_DMPS_DB_WARMBOOT______

int32
sys_usw_dmps_dump_db(uint8 lchip, sal_file_t p_f,ctc_global_dump_db_t* p_dump_param)
{
    uint8  db_type      = 0;
    uint8  is_pass      = TRUE;
    uint16 item_id      = 0;
    uint32 db_item_size = 0;
    int32  ret          = 0;
    void*  p_db         = NULL;
    uint32 valid_count  = 0;
    ctc_slistnode_t* node                = NULL;
    dmps_mapping_db_public_info_t* p_map = NULL;
    sys_dmps_mapping_set_t* dest_node    = NULL;
    uint32 loop = 0;
    char *db_str[DMPS_DB_TYPE_BUTT] = {"Port", "Mac", "PSD", "LSD", "PCS", "Chan", "Chan_rx"};
    uint16 max_num[DMPS_DB_TYPE_BUTT] =
    {
        DMPS_MAX_PORT_NUM, 
        DMPS_MAX_MAC_NUM, 
        DMPS_MAX_SERDES_NUM, 
        DMPS_MAX_SERDES_NUM,
        DMPS_MAX_PCS_NUM,
        DMPS_MAX_CHAN_NUM,
        DMPS_MAX_CHAN_NUM
    };

    SYS_DUMP_DB_LOG(p_f, "%s\n", "# Dmps");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "{");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Master config:");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------");
    SYS_DUMP_DB_LOG(p_f, "%-26s\n", "Ext lport map");
    SYS_DMPS_DB_LOCK(lchip);
    for(loop=0; loop<DMPS_MAX_PORT_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-10u", p_usw_dmps_db_master[lchip]->ext_lport_map[loop]);
        valid_count++;
        if (valid_count % 20 == 0)
        {
            SYS_DUMP_DB_LOG(p_f, "\n");
        }
    }
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%-26s\n", "Cpumac map");
    SYS_DUMP_DB_LOG(p_f, "%-26s%-26s\n", "Is network", "Lport");
    for(loop=0; loop<DMPS_MAX_NUM_CPUMAC_MAP; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-26u%-26u",p_usw_dmps_db_master[lchip]->cpumac_map[loop].is_network, p_usw_dmps_db_master[lchip]->cpumac_map[loop].lport);
        SYS_DUMP_DB_LOG(p_f, "\n");
    }
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%-26s\n", "Mac group is valid");
    for(loop=0; loop<DMPS_MAX_CORE_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-26u", p_usw_dmps_db_master[lchip]->mac_group_is_valid[loop]);
    }
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%-26s\n", "Cpumac dport");
    for(loop=0; loop<DMPS_MAX_NUM_CPUMAC_MAP; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-26u", p_usw_dmps_db_master[lchip]->cpumac_dport[loop]);
    }
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Dmps db port config:");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------------------------------------------------");

    SYS_DUMP_DB_LOG(p_f, "%-9s%-9s%-10s%-9s%-9s%-9s%-9s%-9s%-9s%-9s%-10s%-9s%-9s%-15s%-15s%-9s%-9s%-9s%-9s%-9s%-9s%-9s\n", 
        "Dport id","Port idx", "Port type", "If type", "If mode", "Fec type", "An fec", "An mode", "Mdio map", "Phy map", "Devno map"
        , "An en", "Old cl73", "Link intr en", "Link status", "Unidir en", "Rx rst", "Is ctle", "Xpipe en", "Is an1st", 
        "link fsm", "link mode");
    
    for (loop = 0; loop < DMPS_MAX_PORT_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-9u%-9u%-10u%-9u%-9u%-9u%-9u%-9u%-9u%-9u%-10u%-9u%-9u%-15u%-15u%-9u%-9u%-9u%-9u%-9u%-9u%-9u\n", 
           loop,DMPS_DB_PORT(loop).port_idx&0x7,DMPS_DB_PORT(loop).port_type,DMPS_DB_PORT(loop).if_type,DMPS_DB_PORT(loop).if_mode,
           DMPS_DB_PORT(loop).fec_type,DMPS_DB_PORT(loop).an_fec,DMPS_DB_PORT(loop).an_mode,DMPS_DB_PORT(loop).mdio_map,
           DMPS_DB_PORT(loop).phy_map,DMPS_DB_PORT(loop).devno_map,DMPS_DB_PORT(loop).an_en,DMPS_DB_PORT(loop).old_cl73_status,
           DMPS_DB_PORT(loop).link_intr_en,DMPS_DB_PORT(loop).link_status,DMPS_DB_PORT(loop).unidir_en,DMPS_DB_PORT(loop).rx_rst_hold,
           DMPS_DB_PORT(loop).is_ctle_running,DMPS_DB_PORT(loop).xpipe_en,DMPS_DB_PORT(loop).is_an_first,
           DMPS_DB_PORT(loop).link_fsm, DMPS_DB_PORT(loop).link_mode);
    }
    
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Dmps db mac config:");
    
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------------------------------------------------");

    SYS_DUMP_DB_LOG(p_f, "%-9s%-16s%-16s%-16s%-9s\n", 
        "Mac id","Mac speed", "Mac group id", "Mac idx", "En");
    
    for (loop = 0; loop < DMPS_MAX_MAC_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-9u%-16u%-16u%-16u%-9u\n", 
           loop,DMPS_DB_MAC(loop).mac_speed,DMPS_DB_MAC(loop).mac_group_id,DMPS_DB_MAC(loop).mac_idx,DMPS_DB_MAC(loop).en);
    }
    
    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Dmps db pcs config:");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------");

    SYS_DUMP_DB_LOG(p_f, "%-9s%-9s%-9s\n", 
        "Pcs id","Pcs idx", "Rx rst en");
    
    for (loop = 0; loop < DMPS_MAX_PCS_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-9u%-9u%-9u\n", 
           loop,DMPS_DB_PCS(loop).pcs_idx,DMPS_DB_PCS(loop).rx_rst_en);
    }

    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Dmps db channel config:");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------");

    SYS_DUMP_DB_LOG(p_f, "%-9s%-9s%-9s%-9s%-9s%-13s%-16s%-13s%-15s%-9s%-9s\n", 
        "Chan id","Core id", "Pp id", "Dp id", "Txqm id","Sub chan id","Mac client id", "Speed mode", "Speed vlaue", "Prio", "Is rsv");
    
    for (loop = 0; loop < DMPS_MAX_CHAN_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-9u%-9u%-9u%-9u%-9u%-13u%-16u%-13u%-15u%-9u%-9u\n", 
           loop,DMPS_DB_CHAN(loop).core_id,DMPS_DB_CHAN(loop).pp_id,DMPS_DB_CHAN(loop).dp_id,DMPS_DB_CHAN(loop).txqm_id,
           DMPS_DB_CHAN(loop).sub_chan_id,DMPS_DB_CHAN(loop).mac_client_id,DMPS_DB_CHAN(loop).speed_mode,
           DMPS_DB_CHAN(loop).speed_value,DMPS_DB_CHAN(loop).prio,DMPS_DB_CHAN(loop).is_rsv);
    }

    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Dmps db channel rx config:");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------");

    SYS_DUMP_DB_LOG(p_f, "%-9s%-9s%-9s%-9s%-9s%-13s%-16s%-13s%-15s%-9s%-9s\n", 
        "Chan id","Core id", "Pp id", "Dp id", "Txqm id","Sub chan id","Mac client id", "Speed mode", "Speed vlaue", "Prio", "Is rsv");
    
    for (loop = 0; loop < DMPS_MAX_CHAN_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-9u%-9u%-9u%-9u%-9u%-13u%-16u%-13u%-15u%-9u%-9u\n", 
           loop,DMPS_DB_CHAN_RX(loop).core_id,DMPS_DB_CHAN_RX(loop).pp_id,DMPS_DB_CHAN_RX(loop).dp_id,DMPS_DB_CHAN_RX(loop).txqm_id,
           DMPS_DB_CHAN_RX(loop).sub_chan_id,DMPS_DB_CHAN_RX(loop).mac_client_id,DMPS_DB_CHAN_RX(loop).speed_mode,
           DMPS_DB_CHAN_RX(loop).speed_value,DMPS_DB_CHAN_RX(loop).prio,DMPS_DB_CHAN_RX(loop).is_rsv);
    }

    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Dmps db physical serdes config:");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------");

    SYS_DUMP_DB_LOG(p_f, "%-13s%-9s%-9s%-13s%-13s%-19s%-13s%-13s%-19s%-13s\n", 
        "Serdes id","Pll sel", "Rate div", "Bit width", "Rx polarity","Support speed","Tx polarity", "Ocs", "Physical lane id", "Serdes speed");
    
    for (loop = 0; loop < DMPS_MAX_SERDES_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-13u%-9u%-9u%-13u%-13u%-19u%-13u%-13u%-19u%-13u\n", 
           loop,DMPS_DB_PSD(loop).pll_sel&0x3,DMPS_DB_PSD(loop).rate_div&0x7,DMPS_DB_PSD(loop).bit_width&0x1f,DMPS_DB_PSD(loop).rx_polarity&0x1,
           DMPS_DB_PSD(loop).support_speed&0x1f,DMPS_DB_PSD(loop).tx_polarity&0x1,DMPS_DB_PSD(loop).ocs&0x1f,DMPS_DB_PSD(loop).physical_lane_id&0xff,DMPS_DB_PSD(loop).serdes_speed);
    }

    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Dmps db logic serdes config:");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------");

    SYS_DUMP_DB_LOG(p_f, "%-13s%-23s%-13s%-13s\n", 
        "Serdes id", "Logical lane id", "Pcs l idx", "Hss id");
    
    for (loop = 0; loop < DMPS_MAX_SERDES_NUM; loop++)
    {
        SYS_DUMP_DB_LOG(p_f, "%-13u%-23u%-13u%-13u\n", 
           loop,DMPS_DB_LSD(loop).logical_lane_id,DMPS_DB_LSD(loop).pcs_l_idx,DMPS_DB_LSD(loop).hss_id);
    }

    SYS_DUMP_DB_LOG(p_f, "\n");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "Dmps db map config:");
    SYS_DUMP_DB_LOG(p_f, "%s\n", "--------------------------------------------------------------------------------------------");
    SYS_DUMP_DB_LOG(p_f, "%-13s%-13s%-25s%-25s%-25s%-13s%-13s\n", "Dport", "Chan id", "Chan rx id", "Logic serdes id", "Physical serdes id", "Mac id", "Pcs id");
    CTC_SLIST_LOOP(&(p_usw_dmps_db_master[lchip]->map_node_list), node)
    {
        dest_node = (sys_dmps_mapping_set_t*)node;
        SYS_DUMP_DB_LOG(p_f, "%-13u%-13u%-25u%-25u%-25u%-13u%-13u\n", dest_node->dport, dest_node->chan_id, dest_node->chan_rx_id, dest_node->lsd, dest_node->psd, dest_node->mac_id, dest_node->pcs_id);
    }
    
    SYS_DUMP_DB_LOG(p_f, "\n");
    sys_usw_opf_fprint_alloc_used_info(lchip, (uint8) p_usw_dmps_db_master[lchip]->opf_type_dmps_db, p_f);
    SYS_DUMP_DB_LOG(p_f, "\n");

    for(db_type = 0; db_type < DMPS_DB_TYPE_BUTT; db_type ++)
    {
        SYS_DUMP_DB_LOG(p_f, "*******************************************************************\n");
        SYS_DUMP_DB_LOG(p_f, "  check %s DB \n", db_str[db_type]);
        SYS_DUMP_DB_LOG(p_f, "*******************************************************************\n");
        SYS_DMPS_GET_SIZE(db_type, db_item_size);
        SYS_DMPS_GET_SRC_DB(db_type, p_db);

        is_pass = TRUE;
        for(item_id = 0; item_id < max_num[db_type]; item_id ++)
        {
            p_map = (dmps_mapping_db_public_info_t*)(p_db + item_id * db_item_size);
            ret = _sys_usw_dmps_db_dump_error_check(lchip, db_type, item_id, p_map, p_f);
            is_pass = (is_pass == FALSE) ? FALSE : ((CTC_E_NOT_EXIST == ret) ? FALSE : TRUE);
        }
        if(is_pass)
        {
            SYS_DUMP_DB_LOG(p_f, "    PASS\n");
        }
    }
    SYS_DMPS_DB_UNLOCK(lchip);
    SYS_DUMP_DB_LOG(p_f, "%s\n", "}");

    return CTC_E_NONE;
}

int32
_sys_usw_dmps_db_dump_lsd_db_item(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t fp)
{
    if(title_flag)
    {
        SYS_DUMP_DB_LOG(fp, "%-5s ", "id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "lane_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "l_idx");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "hss_id"); 
        
        SYS_DUMP_DB_LOG(fp, "\n");
    }

    if (!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_LSD, item_id))
    {
        return CTC_E_NONE;
    }

    SYS_DUMP_DB_LOG(fp, "%-5u ",  item_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_LSD(item_id).logical_lane_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_LSD(item_id).pcs_l_idx);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_LSD(item_id).hss_id);
    SYS_DUMP_DB_LOG(fp, "%-5u %-5u %-5u ", DMPS_DB_LSD(item_id).map.id, DMPS_DB_LSD(item_id).map.valid, DMPS_DB_LSD(item_id).map.node_num);
    


    SYS_DUMP_DB_LOG(fp, "\n");
    
    return CTC_E_NONE;
}

int32 _sys_usw_dmps_db_dump_psd_db_item(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t fp)
{

    if(title_flag)
    {
        SYS_DUMP_DB_LOG(fp, "%-5s ",  "id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "is_dyn");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "pll_sel");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "rate_div");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "rx_pol");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "tx_pol"); 
        SYS_DUMP_DB_LOG(fp, "%-6s ",  "ocs");
        SYS_DUMP_DB_LOG(fp, "%-20s ", "speed"); 
        SYS_DUMP_DB_LOG(fp, "%-10s ", "lane_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "bit_width");
        SYS_DUMP_DB_LOG(fp, "%-20s ", "sup_speed");
        
        SYS_DUMP_DB_LOG(fp, "\n");
    }

    if (!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PSD, item_id))
    {
        return CTC_E_NONE;
    }

    SYS_DUMP_DB_LOG(fp, "%-5u ",  item_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PSD(item_id).is_dyn);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PSD(item_id).pll_sel);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PSD(item_id).rate_div);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PSD(item_id).rx_polarity);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PSD(item_id).tx_polarity);
    SYS_DUMP_DB_LOG(fp, "%-6u ",  DMPS_DB_PSD(item_id).ocs);
    SYS_DUMP_DB_LOG(fp, "%-20u ", DMPS_DB_PSD(item_id).serdes_speed);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PSD(item_id).physical_lane_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PSD(item_id).bit_width);
    SYS_DUMP_DB_LOG(fp, "%-20u ", DMPS_DB_PSD(item_id).support_speed);

    SYS_DUMP_DB_LOG(fp, "\n");
    
    return CTC_E_NONE;
}

int32 _sys_usw_dmps_db_dump_pcs_db_item(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t fp)
{
    if(title_flag)
    {
        SYS_DUMP_DB_LOG(fp, "%-5s ", "id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "pcs_idx");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "rx_rst_en");
        
        SYS_DUMP_DB_LOG(fp, "\n");
    }

    if (!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_PCS, item_id))
    {
        return CTC_E_NONE;
    }

    SYS_DUMP_DB_LOG(fp, "%-5u ",  item_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PCS(item_id).pcs_idx);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_PCS(item_id).rx_rst_en);
    
    SYS_DUMP_DB_LOG(fp, "\n");
    
    return CTC_E_NONE;
}

int32 _sys_usw_dmps_db_dump_chan_db_item(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t fp)
{
    if(title_flag)
    {
        SYS_DUMP_DB_LOG(fp, "%-5s ", "id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "core_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "pp_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "dp_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "txqm_id");
        SYS_DUMP_DB_LOG(fp, "%-20s ", "sub_chan");
        SYS_DUMP_DB_LOG(fp, "%-15s ", "mac_client");
        SYS_DUMP_DB_LOG(fp, "%-15s ", "speed_mode");
        SYS_DUMP_DB_LOG(fp, "%-15s ", "speed_value");
        
        SYS_DUMP_DB_LOG(fp, "\n");
    }

    if (!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN, item_id))
    {
        return CTC_E_NONE;
    }

    SYS_DUMP_DB_LOG(fp, "%-5u ",  item_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_CHAN(item_id).core_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_CHAN(item_id).pp_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_CHAN(item_id).dp_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_CHAN(item_id).txqm_id);
    SYS_DUMP_DB_LOG(fp, "%-20u ", DMPS_DB_CHAN(item_id).sub_chan_id);
    SYS_DUMP_DB_LOG(fp, "%-15u ", DMPS_DB_CHAN(item_id).mac_client_id);
    SYS_DUMP_DB_LOG(fp, "%-15u ", DMPS_DB_CHAN(item_id).speed_mode);
    SYS_DUMP_DB_LOG(fp, "%-15u ", DMPS_DB_CHAN(item_id).speed_value);
    
    SYS_DUMP_DB_LOG(fp, "\n");
    
    return CTC_E_NONE;
}

int32 _sys_usw_dmps_db_dump_chan_rx_db_item(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t fp)
{
    if(title_flag)
    {
        SYS_DUMP_DB_LOG(fp, "%-5s ", "id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "core_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "pp_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "dp_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "txqm_id");
        SYS_DUMP_DB_LOG(fp, "%-20s ", "sub_chan");
        SYS_DUMP_DB_LOG(fp, "%-15s ", "mac_client");
        SYS_DUMP_DB_LOG(fp, "%-15s ", "speed_mode");
        SYS_DUMP_DB_LOG(fp, "%-15s ", "speed_value");
        
        SYS_DUMP_DB_LOG(fp, "\n");
    }

    if (!_sys_usw_dmps_db_is_valid_id(lchip, DMPS_DB_TYPE_CHAN_RX, item_id))
    {
        return CTC_E_NONE;
    }

    SYS_DUMP_DB_LOG(fp, "%-5u ",  item_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_CHAN_RX(item_id).core_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_CHAN_RX(item_id).pp_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_CHAN_RX(item_id).dp_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", DMPS_DB_CHAN_RX(item_id).txqm_id);
    SYS_DUMP_DB_LOG(fp, "%-20u ", DMPS_DB_CHAN_RX(item_id).sub_chan_id);
    SYS_DUMP_DB_LOG(fp, "%-15u ", DMPS_DB_CHAN_RX(item_id).mac_client_id);
    SYS_DUMP_DB_LOG(fp, "%-15u ", DMPS_DB_CHAN_RX(item_id).speed_mode);
    SYS_DUMP_DB_LOG(fp, "%-15u ", DMPS_DB_CHAN_RX(item_id).speed_value);
    
    SYS_DUMP_DB_LOG(fp, "\n");
    
    return CTC_E_NONE;
}

int32 _sys_usw_dmps_db_dump_mapping(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t fp)
{
    uint16 loop_item_id = 0;
    sys_dmps_mapping_set_t* p_map_node  = NULL;
    ctc_slistnode_t* node               = NULL;

    if(title_flag)
    {
        SYS_DUMP_DB_LOG(fp, "%-5s ",  "id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "dport");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "mac_id");
        SYS_DUMP_DB_LOG(fp, "%-20s ", "psd");
        SYS_DUMP_DB_LOG(fp, "%-20s ", "lsd");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "pcs_id");
        SYS_DUMP_DB_LOG(fp, "%-10s ", "chan_id");
        SYS_DUMP_DB_LOG(fp, "%-15s ", "chan_rx_id");
        
        SYS_DUMP_DB_LOG(fp, "\n");
    }
    
    CTC_SLIST_LOOP(&(p_usw_dmps_db_master[lchip]->map_node_list), node)
    {
        if(loop_item_id == item_id)
        {
            p_map_node = _ctc_container_of(node, sys_dmps_mapping_set_t, head);
            break;
        }
        
        loop_item_id ++;
    }

    if(NULL == p_map_node)
    {
        SYS_DUMP_DB_LOG(fp, "Don't Support!\n");
        return CTC_E_NOT_SUPPORT;
    }

    SYS_DUMP_DB_LOG(fp, "%-5u ",  item_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", p_map_node->dport);
    SYS_DUMP_DB_LOG(fp, "%-10u ", p_map_node->mac_id);
    SYS_DUMP_DB_LOG(fp, "%-20u ", p_map_node->psd);
    SYS_DUMP_DB_LOG(fp, "%-20u ", p_map_node->lsd);
    SYS_DUMP_DB_LOG(fp, "%-10u ", p_map_node->pcs_id);
    SYS_DUMP_DB_LOG(fp, "%-10u ", p_map_node->chan_id);
    SYS_DUMP_DB_LOG(fp, "%-15u ", p_map_node->chan_rx_id);

    SYS_DUMP_DB_LOG(fp, "\n");
                    
    return CTC_E_NONE;
}


int32
_sys_usw_dmps_db_dump(uint8 lchip, uint8 db_type, sal_file_t fp)
{
    uint16 mapping_db_item_cnt = 0;
    uint32 max_num = 0;
    uint32 item_id = 0;
    char *db_str[] = 
    {
        "Port", "Mac", "Physical SerDes", "Logical SerDes", "PCS", "Chan", "Chan Rx", "Mapping"
    };
    ctc_slistnode_t* node = NULL;
    int32 (*dump_db_item_info)(uint8 lchip, uint16 item_id, uint8 title_flag, sal_file_t p_fp) = NULL;
    
    switch(db_type)
    {
        case DMPS_DB_TYPE_PORT:
            max_num = DMPS_MAX_PORT_NUM;
            dump_db_item_info = _sys_usw_dmps_db_dump_port_db_item;
            break;
        case DMPS_DB_TYPE_MAC:
            max_num = DMPS_MAX_MAC_NUM;
            dump_db_item_info = _sys_usw_dmps_db_dump_mac_db_item;
            break;
        case DMPS_DB_TYPE_LSD:
            max_num = DMPS_MAX_SERDES_NUM;
            dump_db_item_info = _sys_usw_dmps_db_dump_lsd_db_item;
            break;
        case DMPS_DB_TYPE_PSD:
            max_num = DMPS_MAX_SERDES_NUM;
            dump_db_item_info = _sys_usw_dmps_db_dump_psd_db_item;
            break;
        case DMPS_DB_TYPE_PCS:
            max_num = DMPS_MAX_PCS_NUM;
            dump_db_item_info = _sys_usw_dmps_db_dump_pcs_db_item;
            break;
        case DMPS_DB_TYPE_CHAN:
            max_num = DMPS_MAX_CHAN_NUM;
            dump_db_item_info = _sys_usw_dmps_db_dump_chan_db_item;
            break;
        case DMPS_DB_TYPE_CHAN_RX:
            max_num = DMPS_MAX_CHAN_NUM;
            dump_db_item_info = _sys_usw_dmps_db_dump_chan_rx_db_item;
            break;
        case DMPS_DB_TYPE_BUTT:
            dump_db_item_info = _sys_usw_dmps_db_dump_mapping;
            break;
        default:
            return CTC_E_INVALID_PARAM;
    }
        
    if(DMPS_DB_TYPE_BUTT == db_type)
    {
        CTC_SLIST_LOOP(&(p_usw_dmps_db_master[lchip]->map_node_list), node)
        {
            mapping_db_item_cnt ++;
        }
        max_num = mapping_db_item_cnt;
    }
    
    SYS_DUMP_DB_LOG(fp, "**********************************************************************************************************************\n");
    SYS_DUMP_DB_LOG(fp, "    %s DB Info\n", db_str[db_type]);
    SYS_DUMP_DB_LOG(fp, "**********************************************************************************************************************\n");
    for(item_id = 0; item_id < max_num; item_id ++)
    {
        (void)dump_db_item_info(lchip, item_id, !item_id, fp);
    }

    return CTC_E_NONE;
}

int32
_sys_usw_dmps_port_wb_sync(uint8 lchip,ctc_wb_data_t *wb_data)
{
    uint32 max_entry_cnt = 0;
    uint32 dport = 0;
    sys_wb_dmps_port_t* p_wb_port_dmps_port = NULL;

    max_entry_cnt =  wb_data->buffer_len / (wb_data->key_len + wb_data->data_len);
    for (dport = 0; dport < DMPS_MAX_PORT_NUM; dport++)
    {
        p_wb_port_dmps_port = (sys_wb_dmps_port_t *)wb_data->buffer + wb_data->valid_cnt;

        p_wb_port_dmps_port->port_id         = dport;
        p_wb_port_dmps_port->port_idx        = DMPS_DB_PORT(dport).port_idx & 0x7;
        p_wb_port_dmps_port->port_type       = DMPS_DB_PORT(dport).port_type;
        p_wb_port_dmps_port->if_type         = DMPS_DB_PORT(dport).if_type;
        p_wb_port_dmps_port->if_mode         = DMPS_DB_PORT(dport).if_mode;
        p_wb_port_dmps_port->fec_type        = DMPS_DB_PORT(dport).fec_type;
        p_wb_port_dmps_port->an_fec          = DMPS_DB_PORT(dport).an_fec;
        p_wb_port_dmps_port->is_rsv          = DMPS_DB_PORT(dport).is_rsv;
        p_wb_port_dmps_port->an_mode         = DMPS_DB_PORT(dport).an_mode;
        p_wb_port_dmps_port->mdio_map        = DMPS_DB_PORT(dport).mdio_map;
        p_wb_port_dmps_port->phy_map         = DMPS_DB_PORT(dport).phy_map;
        p_wb_port_dmps_port->devno_map       = DMPS_DB_PORT(dport).devno_map;
        sal_memcpy(&p_wb_port_dmps_port->an_ability, &(DMPS_DB_PORT(dport).an_ability), sizeof(sys_dmps_an_ability_t));
        p_wb_port_dmps_port->an_en           = DMPS_DB_PORT(dport).an_en;
        p_wb_port_dmps_port->old_cl73_status = DMPS_DB_PORT(dport).old_cl73_status;
        p_wb_port_dmps_port->link_intr_en    = DMPS_DB_PORT(dport).link_intr_en;
        p_wb_port_dmps_port->link_status     = DMPS_DB_PORT(dport).link_status;
        p_wb_port_dmps_port->unidir_en       = DMPS_DB_PORT(dport).unidir_en;
        p_wb_port_dmps_port->rx_rst_hold     = DMPS_DB_PORT(dport).rx_rst_hold;
        p_wb_port_dmps_port->is_ctle_running = DMPS_DB_PORT(dport).is_ctle_running;
        p_wb_port_dmps_port->xpipe_en        = DMPS_DB_PORT(dport).xpipe_en;
        p_wb_port_dmps_port->is_an_first     = DMPS_DB_PORT(dport).is_an_first;
        p_wb_port_dmps_port->link_fsm        = DMPS_DB_PORT(dport).link_fsm;
        p_wb_port_dmps_port->link_mode       = DMPS_DB_PORT(dport).link_mode;

        if (++wb_data->valid_cnt == max_entry_cnt)
        {
            CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
            wb_data->valid_cnt = 0;
        }
    }
    if (wb_data->valid_cnt > 0)
    {
        CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
        wb_data->valid_cnt = 0;
    }
    return CTC_E_NONE;
}

int32
_sys_usw_dmps_mac_wb_sync(uint8 lchip,ctc_wb_data_t *wb_data)
{
    uint32 max_entry_cnt = 0;
    uint32 mac_id = 0;
    sys_wb_dmps_mac_t* p_wb_port_dmps_mac = NULL;

    max_entry_cnt =  wb_data->buffer_len / (wb_data->key_len + wb_data->data_len);
    for (mac_id = 0; mac_id < DMPS_MAX_MAC_NUM; mac_id++)
    {
        p_wb_port_dmps_mac = (sys_wb_dmps_mac_t *)wb_data->buffer + wb_data->valid_cnt;

        p_wb_port_dmps_mac->mac_id       = mac_id;
        p_wb_port_dmps_mac->mac_speed    = DMPS_DB_MAC(mac_id).mac_speed;
        p_wb_port_dmps_mac->mac_group_id = DMPS_DB_MAC(mac_id).mac_group_id;
        p_wb_port_dmps_mac->mac_idx      = DMPS_DB_MAC(mac_id).mac_idx;
        p_wb_port_dmps_mac->en           = DMPS_DB_MAC(mac_id).en;

        if (++wb_data->valid_cnt == max_entry_cnt)
        {
            CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
            wb_data->valid_cnt = 0;
        }
    }
    if (wb_data->valid_cnt > 0)
    {
        CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
        wb_data->valid_cnt = 0;
    }

    return CTC_E_NONE;
}


int32
_sys_usw_dmps_pcs_wb_sync(uint8 lchip,ctc_wb_data_t *wb_data)
{
    uint32 max_entry_cnt = 0;
    uint32 pcs_id = 0;
    sys_wb_dmps_pcs_t* p_wb_port_dmps_pcs = NULL;

    max_entry_cnt =  wb_data->buffer_len / (wb_data->key_len + wb_data->data_len);
    for (pcs_id = 0; pcs_id < DMPS_MAX_PCS_NUM; pcs_id++)
    {
        p_wb_port_dmps_pcs = (sys_wb_dmps_pcs_t *)wb_data->buffer + wb_data->valid_cnt;

        p_wb_port_dmps_pcs->pcs_id    = pcs_id;
        p_wb_port_dmps_pcs->pcs_idx   = DMPS_DB_PCS(pcs_id).pcs_idx;
        p_wb_port_dmps_pcs->rx_rst_en = DMPS_DB_PCS(pcs_id).rx_rst_en;

        if (++wb_data->valid_cnt == max_entry_cnt)
        {
            CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
            wb_data->valid_cnt = 0;
        }
    }
    if (wb_data->valid_cnt > 0)
    {
        CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
        wb_data->valid_cnt = 0;
    }

    return CTC_E_NONE;
}

int32
_sys_usw_dmps_chan_wb_sync(uint8 lchip,ctc_wb_data_t *wb_data)
{
    uint32 max_entry_cnt = 0;
    uint32 chan_id = 0;
    sys_wb_dmps_chan_t* p_wb_port_dmps_chan = NULL;

    max_entry_cnt =  wb_data->buffer_len / (wb_data->key_len + wb_data->data_len);
    for (chan_id = 0; chan_id < DMPS_MAX_CHAN_NUM; chan_id++)
    {
        p_wb_port_dmps_chan = (sys_wb_dmps_chan_t *)wb_data->buffer + wb_data->valid_cnt;

        p_wb_port_dmps_chan->chan_id       = chan_id;
        p_wb_port_dmps_chan->core_id       = DMPS_DB_CHAN(chan_id).core_id;
        p_wb_port_dmps_chan->pp_id         = DMPS_DB_CHAN(chan_id).pp_id;
        p_wb_port_dmps_chan->dp_id         = DMPS_DB_CHAN(chan_id).dp_id;
        p_wb_port_dmps_chan->txqm_id       = DMPS_DB_CHAN(chan_id).txqm_id;
        p_wb_port_dmps_chan->sub_chan_id   = DMPS_DB_CHAN(chan_id).sub_chan_id;
        p_wb_port_dmps_chan->mac_client_id = DMPS_DB_CHAN(chan_id).mac_client_id;
        p_wb_port_dmps_chan->speed_mode    = DMPS_DB_CHAN(chan_id).speed_mode;
        p_wb_port_dmps_chan->is_rsv        = DMPS_DB_CHAN(chan_id).is_rsv;
        p_wb_port_dmps_chan->prio          = DMPS_DB_CHAN(chan_id).prio;
        p_wb_port_dmps_chan->speed_value   = DMPS_DB_CHAN(chan_id).speed_value;

        if (++wb_data->valid_cnt == max_entry_cnt)
        {
            CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
            wb_data->valid_cnt = 0;
        }
    }
    if (wb_data->valid_cnt > 0)
    {
        CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
        wb_data->valid_cnt = 0;
    }

    return CTC_E_NONE;
}

int32
_sys_usw_dmps_chan_rx_wb_sync(uint8 lchip,ctc_wb_data_t *wb_data)
{
    uint32 max_entry_cnt = 0;
    uint32 chan_id = 0;
    sys_wb_dmps_chan_rx_t* p_wb_port_dmps_chan_rx = NULL;

    max_entry_cnt =  wb_data->buffer_len / (wb_data->key_len + wb_data->data_len);
    for (chan_id = 0; chan_id < DMPS_MAX_CHAN_NUM; chan_id++)
    {
        p_wb_port_dmps_chan_rx = (sys_wb_dmps_chan_rx_t *)wb_data->buffer + wb_data->valid_cnt;

        p_wb_port_dmps_chan_rx->chan_id       = chan_id;
        p_wb_port_dmps_chan_rx->core_id       = DMPS_DB_CHAN_RX(chan_id).core_id;
        p_wb_port_dmps_chan_rx->pp_id         = DMPS_DB_CHAN_RX(chan_id).pp_id;
        p_wb_port_dmps_chan_rx->dp_id         = DMPS_DB_CHAN_RX(chan_id).dp_id;
        p_wb_port_dmps_chan_rx->txqm_id       = DMPS_DB_CHAN_RX(chan_id).txqm_id;
        p_wb_port_dmps_chan_rx->sub_chan_id   = DMPS_DB_CHAN_RX(chan_id).sub_chan_id;
        p_wb_port_dmps_chan_rx->mac_client_id = DMPS_DB_CHAN_RX(chan_id).mac_client_id;
        p_wb_port_dmps_chan_rx->speed_mode    = DMPS_DB_CHAN_RX(chan_id).speed_mode;
        p_wb_port_dmps_chan_rx->is_rsv        = DMPS_DB_CHAN_RX(chan_id).is_rsv;
        p_wb_port_dmps_chan_rx->prio          = DMPS_DB_CHAN_RX(chan_id).prio;
        p_wb_port_dmps_chan_rx->speed_value   = DMPS_DB_CHAN_RX(chan_id).speed_value;

        if (++wb_data->valid_cnt == max_entry_cnt)
        {
            CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
            wb_data->valid_cnt = 0;
        }
    }
    if (wb_data->valid_cnt > 0)
    {
        CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
        wb_data->valid_cnt = 0;
    }

    return CTC_E_NONE;
}

int32
_sys_usw_dmps_physical_serdes_wb_sync(uint8 lchip,ctc_wb_data_t *wb_data)
{
    uint32 max_entry_cnt = 0;
    uint32 serdes_id = 0;
    sys_wb_dmps_psd_t* p_wb_port_dmps_physical_serdes = NULL;

    max_entry_cnt =  wb_data->buffer_len / (wb_data->key_len + wb_data->data_len);
    for (serdes_id = 0; serdes_id < DMPS_MAX_SERDES_NUM; serdes_id++)
    {
        p_wb_port_dmps_physical_serdes = (sys_wb_dmps_psd_t *)wb_data->buffer + wb_data->valid_cnt;

        p_wb_port_dmps_physical_serdes->serdes_id        = serdes_id;
        p_wb_port_dmps_physical_serdes->is_dyn           = DMPS_DB_PSD(serdes_id).is_dyn;
        p_wb_port_dmps_physical_serdes->pll_sel          = DMPS_DB_PSD(serdes_id).pll_sel&0x3;
        p_wb_port_dmps_physical_serdes->rate_div         = DMPS_DB_PSD(serdes_id).rate_div&0x7;
        p_wb_port_dmps_physical_serdes->bit_width        = DMPS_DB_PSD(serdes_id).bit_width&0x1f;
        p_wb_port_dmps_physical_serdes->rx_polarity      = DMPS_DB_PSD(serdes_id).rx_polarity&0x1;
        p_wb_port_dmps_physical_serdes->support_speed    = DMPS_DB_PSD(serdes_id).support_speed;
        p_wb_port_dmps_physical_serdes->tx_polarity      = DMPS_DB_PSD(serdes_id).tx_polarity&0x1;
        p_wb_port_dmps_physical_serdes->ocs              = DMPS_DB_PSD(serdes_id).ocs&0x1f;
        p_wb_port_dmps_physical_serdes->physical_lane_id = DMPS_DB_PSD(serdes_id).physical_lane_id&0xff;
        p_wb_port_dmps_physical_serdes->serdes_speed     = DMPS_DB_PSD(serdes_id).serdes_speed;

        if (++wb_data->valid_cnt == max_entry_cnt)
        {
            CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
            wb_data->valid_cnt = 0;
        }
    }
    if (wb_data->valid_cnt > 0)
    {
        CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
        wb_data->valid_cnt = 0;
    }

    return CTC_E_NONE;
}

int32
_sys_usw_dmps_db_dump_error_check(uint8 lchip, uint8 db_type, uint16 item_id, dmps_mapping_db_public_info_t* p_map, sal_file_t fp)
{
    uintptr offset                      = 0;
    uint16 *db_item_id                  = 0;
    uint16 index                        = 0;
    uint16 db_map_node_cnt              = 0;
    uint16 cnt                          = 0;
    sys_dmps_mapping_set_t* p_map_node  = NULL;
    ctc_slistnode_t* node               = NULL;
    char *db_str[] = 
    {
        "Port", "Mac", "Physical SerDes", "Logical SerDes", "PCS", "Chan", "Chan Rx"
    };

    for(index = 0; index < DMPS_MAX_NUM_PER_MODULE; index++)
    {
        if(NULL != p_map->node[index])
        {
            db_map_node_cnt++;
        }
    }

    if(db_map_node_cnt != p_map->node_num)
    {
        SYS_DUMP_DB_LOG(fp, "      %s DB @ %d, Error Code 0x1. p_map->node_num = %d, but p_map->node real map num = %d, \n", \
                        db_str[db_type], item_id, p_map->node_num, db_map_node_cnt);
        return CTC_E_NOT_EXIST;
    }

    CTC_SLIST_LOOP(&(p_usw_dmps_db_master[lchip]->map_node_list), node)
    {
        p_map_node = _ctc_container_of(node, sys_dmps_mapping_set_t, head);
        
        switch(db_type)
        {
            case DMPS_DB_TYPE_PORT:
                offset = (uintptr)(&p_map_node->dport) - (uintptr)p_map_node;
                break;
            case DMPS_DB_TYPE_MAC:
                offset = (uintptr)(&p_map_node->mac_id) - (uintptr)p_map_node;
                break;
            case DMPS_DB_TYPE_LSD:
                offset = (uintptr)(&p_map_node->lsd) - (uintptr)p_map_node;
                break;
            case DMPS_DB_TYPE_PSD:
                offset = (uintptr)(&p_map_node->psd) - (uintptr)p_map_node;
                break;
            case DMPS_DB_TYPE_PCS:
                offset = (uintptr)(&p_map_node->pcs_id) - (uintptr)p_map_node;
                break;
            case DMPS_DB_TYPE_CHAN:
                offset = (uintptr)(&p_map_node->chan_id) - (uintptr)p_map_node;
                break;
            case DMPS_DB_TYPE_CHAN_RX:
                offset = (uintptr)(&p_map_node->chan_rx_id) - (uintptr)p_map_node;
                break;
            default:
                return CTC_E_INVALID_PARAM;
        }

        db_item_id = (uint16*)((uintptr)p_map_node + offset);
        if(item_id != (*db_item_id))
        {
            continue;
        }

        for(index = 0; index < DMPS_MAX_NUM_PER_MODULE; index++)
        {
            if((uintptr)p_map_node == ((uintptr)(p_map->node[index])))
            {
                break;
            }
        }

        if(index >= DMPS_MAX_NUM_PER_MODULE)
        {
            SYS_DUMP_DB_LOG(fp, "      %s DB @ %d, Error Code 0x2.\n", db_str[db_type], item_id);
            return CTC_E_NOT_EXIST;
        }

        cnt++;        
    }

    if(cnt != p_map->node_num)
    {
        SYS_DUMP_DB_LOG(fp, "      %s DB @ %d, Error Code 0x3. p_map->node_num = %d, but map_node_list real node_num is %d\n", 
            db_str[db_type], item_id, p_map->node_num, cnt);
        return CTC_E_NOT_EXIST;
    }

    return CTC_E_NONE;
}

int32
sys_usw_dmps_db_dump(uint8 lchip, sal_file_t fp, ctc_global_dump_db_t* p_dump_param)
{
    uint8  db_type                       = 0;
    uint32 db_item_size                  = 0;
    uint8  is_pass                       = TRUE;
    int32  ret                           = 0;
    uint16 item_id                       = 0;
    void*  p_db                          = NULL;
    dmps_mapping_db_public_info_t* p_map = NULL;
    char *db_str[DMPS_DB_TYPE_BUTT] = {"Port", "Mac", "Physical SerDes", "Logical SerDes", "PCS", "Chan", "Chan Rx"};
    uint16 max_num[DMPS_DB_TYPE_BUTT] =
    {
        DMPS_MAX_PORT_NUM, 
        DMPS_MAX_MAC_NUM, 
        DMPS_MAX_SERDES_NUM, 
        DMPS_MAX_SERDES_NUM,
        DMPS_MAX_PCS_NUM,
        DMPS_MAX_CHAN_NUM,
        DMPS_MAX_CHAN_NUM
    };

    SYS_DMPS_DB_LOCK(lchip);
    for(db_type = 0; db_type <= DMPS_DB_TYPE_BUTT; db_type ++)
    {
        (void)_sys_usw_dmps_db_dump(lchip, db_type, fp);
    }
    for(db_type = 0; db_type < DMPS_DB_TYPE_BUTT; db_type ++)
    {
        SYS_DUMP_DB_LOG(fp, "*******************************************************************\n");
        SYS_DUMP_DB_LOG(fp, "  check %s DB \n", db_str[db_type]);
        SYS_DUMP_DB_LOG(fp, "*******************************************************************\n");
        SYS_DMPS_GET_SIZE(db_type, db_item_size);
        SYS_DMPS_GET_SRC_DB(db_type, p_db);

        is_pass = TRUE;
        for(item_id = 0; item_id < max_num[db_type]; item_id ++)
        {
            p_map = (dmps_mapping_db_public_info_t*)(p_db + item_id * db_item_size);
            ret = _sys_usw_dmps_db_dump_error_check(lchip, db_type, item_id, p_map, fp);
            is_pass = (is_pass == FALSE) ? FALSE : ((CTC_E_NOT_EXIST == ret) ? FALSE : TRUE);
        }
        if(is_pass)
        {
            SYS_DUMP_DB_LOG(fp, "    PASS\n");
        }
    }
    SYS_DMPS_DB_UNLOCK(lchip);

    return CTC_E_NONE;
}

int32
_sys_usw_dmps_logic_serdes_wb_sync(uint8 lchip,ctc_wb_data_t *wb_data)
{
    uint32 max_entry_cnt = 0;
    uint32 serdes_id = 0;
    sys_wb_dmps_lsd_t* p_wb_port_dmps_logic_serdes = NULL;

    max_entry_cnt =  wb_data->buffer_len / (wb_data->key_len + wb_data->data_len);
    for (serdes_id = 0; serdes_id < DMPS_MAX_SERDES_NUM; serdes_id++)
    {
        p_wb_port_dmps_logic_serdes = (sys_wb_dmps_lsd_t *)wb_data->buffer + wb_data->valid_cnt;

        p_wb_port_dmps_logic_serdes->serdes_id       = serdes_id;
        p_wb_port_dmps_logic_serdes->logical_lane_id = DMPS_DB_LSD(serdes_id).logical_lane_id;
        p_wb_port_dmps_logic_serdes->pcs_l_idx       = DMPS_DB_LSD(serdes_id).pcs_l_idx;
        p_wb_port_dmps_logic_serdes->hss_id          = DMPS_DB_LSD(serdes_id).hss_id;

        if (++wb_data->valid_cnt == max_entry_cnt)
        {
            CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
            wb_data->valid_cnt = 0;
        }
    }
    if (wb_data->valid_cnt > 0)
    {
        CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
        wb_data->valid_cnt = 0;
    }

    return CTC_E_NONE;
}


int32
_sys_usw_dmps_map_wb_sync(uint8 lchip,ctc_wb_data_t *wb_data)
{
    uint32 max_entry_cnt = 0;
    sys_wb_dmps_map_t* p_wb_port_dmps_map = NULL;
    ctc_slistnode_t* node = NULL;
    sys_dmps_mapping_set_t* dest_node = NULL;

    max_entry_cnt =  wb_data->buffer_len / (wb_data->key_len + wb_data->data_len);

    CTC_SLIST_LOOP(&(p_usw_dmps_db_master[lchip]->map_node_list), node)
    {
        p_wb_port_dmps_map = (sys_wb_dmps_map_t *)wb_data->buffer + wb_data->valid_cnt;
        dest_node = (sys_dmps_mapping_set_t*)node;

        p_wb_port_dmps_map->dport_id           = dest_node->dport;
        p_wb_port_dmps_map->chan_id            = dest_node->chan_id;
        p_wb_port_dmps_map->chan_rx_id         = dest_node->chan_rx_id;
        p_wb_port_dmps_map->logic_serdes_id    = dest_node->lsd;
        p_wb_port_dmps_map->physical_serdes_id = dest_node->psd;
        p_wb_port_dmps_map->mac_id             = dest_node->mac_id;
        p_wb_port_dmps_map->pcs_id             = dest_node->pcs_id;

        if (++wb_data->valid_cnt == max_entry_cnt)
        {
            CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
            wb_data->valid_cnt = 0;
        }
    }

    if (wb_data->valid_cnt > 0)
    {
        CTC_ERROR_RETURN(ctc_wb_add_entry(wb_data));
        wb_data->valid_cnt = 0;
    }

    return CTC_E_NONE;
}

int32 sys_usw_dmps_wb_sync_master(uint8 lchip, uint32 app_id)
{
    int32 ret = CTC_E_NONE;
    ctc_wb_data_t wb_data = {0};
    sys_wb_dmps_master_t* dmps_master = NULL;

    CTC_WB_ALLOC_BUFFER(&wb_data.buffer);
    SYS_DMPS_DB_LOCK(lchip);
    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER)
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_master_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER);
        dmps_master = (sys_wb_dmps_master_t *) wb_data.buffer;
        if (NULL == dmps_master)
        {
            ret = CTC_E_NO_MEMORY;
            goto done;
        }

        dmps_master->lchip = lchip;
        sal_memcpy(dmps_master->ext_lport_map, p_usw_dmps_db_master[lchip]->ext_lport_map, sizeof(uint16)*DMPS_MAX_PORT_NUM);
        sal_memcpy(dmps_master->cpumac_map, p_usw_dmps_db_master[lchip]->cpumac_map, sizeof(sys_dmps_db_cpumac_map_t)*DMPS_MAX_NUM_CPUMAC_MAP);
        sal_memcpy(dmps_master->mac_group_is_valid, p_usw_dmps_db_master[lchip]->mac_group_is_valid, sizeof(uint32)*DMPS_MAX_CORE_NUM);
        sal_memcpy(dmps_master->cpumac_dport, p_usw_dmps_db_master[lchip]->cpumac_dport, sizeof(uint16)*DMPS_MAX_NUM_CPUMAC_MAP);
        sal_memcpy(dmps_master->chan_2_logic_serdes, p_usw_dmps_db_master[lchip]->chan_2_logic_serdes, \
                                                     sizeof(sys_dmps_db_chan2lsd_map_t)*DMPS_MAX_CORE_NUM*DMPS_NW_CPU_NUM_PER_CORE);
        dmps_master->xpipe_alloc = p_usw_dmps_db_master[lchip]->xpipe_alloc;
        wb_data.valid_cnt = 1;
        CTC_ERROR_GOTO(ctc_wb_add_entry(&wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER);
    }

    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_PORT )
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_port_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT);
        CTC_ERROR_GOTO(_sys_usw_dmps_port_wb_sync(lchip, &wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT);
    }
    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_MAC )
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_mac_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAC);
        CTC_ERROR_GOTO(_sys_usw_dmps_mac_wb_sync(lchip, &wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAC);
    }
    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_PCS )
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_pcs_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PCS);
        CTC_ERROR_GOTO(_sys_usw_dmps_pcs_wb_sync(lchip, &wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PCS);
    }
    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN )
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_chan_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN);
        CTC_ERROR_GOTO(_sys_usw_dmps_chan_wb_sync(lchip, &wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN);
    }
    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN_RX )
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_chan_rx_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN_RX);
        CTC_ERROR_GOTO(_sys_usw_dmps_chan_rx_wb_sync(lchip, &wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN_RX);
    }
    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_PSD )
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_psd_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD);
        CTC_ERROR_GOTO(_sys_usw_dmps_physical_serdes_wb_sync(lchip, &wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD);
    }
    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_LSD )
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_lsd_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_LSD);
        CTC_ERROR_GOTO(_sys_usw_dmps_logic_serdes_wb_sync(lchip, &wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_LSD);
    }
    if (app_id == 0 || CTC_WB_SUBID(app_id) == SYS_WB_APPID_DMPS_DMPS_SUBID_MAP )
    {
        CTC_WB_INIT_DATA_T((&wb_data), sys_wb_dmps_map_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAP);
        CTC_ERROR_GOTO(_sys_usw_dmps_map_wb_sync(lchip, &wb_data), ret, done);
        CTC_WB_SYNC_END_DATA(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAP);
    }
    done:
    SYS_DMPS_DB_UNLOCK(lchip);
    CTC_WB_FREE_BUFFER(wb_data.buffer);

    return ret;
}


int32
_sys_usw_dmps_port_wb_restore(uint8 lchip,  ctc_wb_query_t *wb_query)
{
    uint32 entry_cnt = 0;
    int32 ret = CTC_E_NONE;
    sys_wb_dmps_port_t  wb_port_prop = {0};
    
    CTC_WB_INIT_QUERY_T(wb_query, sys_wb_dmps_port_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT);
    CTC_WB_QUERY_ENTRY_BEGIN(wb_query);

        sal_memcpy((uint8*)&wb_port_prop, (uint8*)(wb_query->buffer) + entry_cnt * (wb_query->key_len + wb_query->data_len), wb_query->key_len + wb_query->data_len);
        entry_cnt++;

        DMPS_DB_PORT(wb_port_prop.port_id).port_idx = wb_port_prop.port_idx;
        DMPS_DB_PORT(wb_port_prop.port_id).port_type = wb_port_prop.port_type;
        DMPS_DB_PORT(wb_port_prop.port_id).if_type         = wb_port_prop.if_type;
        DMPS_DB_PORT(wb_port_prop.port_id).if_mode         = wb_port_prop.if_mode;
        DMPS_DB_PORT(wb_port_prop.port_id).fec_type        = wb_port_prop.fec_type;
        DMPS_DB_PORT(wb_port_prop.port_id).an_fec          = wb_port_prop.an_fec;
        DMPS_DB_PORT(wb_port_prop.port_id).is_rsv          = wb_port_prop.is_rsv;
        DMPS_DB_PORT(wb_port_prop.port_id).an_mode         = wb_port_prop.an_mode;
        DMPS_DB_PORT(wb_port_prop.port_id).mdio_map        = wb_port_prop.mdio_map;
        DMPS_DB_PORT(wb_port_prop.port_id).phy_map         = wb_port_prop.phy_map;
        DMPS_DB_PORT(wb_port_prop.port_id).devno_map       = wb_port_prop.devno_map;
        sal_memcpy(&DMPS_DB_PORT(wb_port_prop.port_id).an_ability, &(wb_port_prop.an_ability), sizeof(sys_dmps_an_ability_t));
        DMPS_DB_PORT(wb_port_prop.port_id).an_en           = wb_port_prop.an_en;
        DMPS_DB_PORT(wb_port_prop.port_id).old_cl73_status = wb_port_prop.old_cl73_status;
        DMPS_DB_PORT(wb_port_prop.port_id).link_intr_en    = wb_port_prop.link_intr_en;
        DMPS_DB_PORT(wb_port_prop.port_id).link_status     = wb_port_prop.link_status;
        DMPS_DB_PORT(wb_port_prop.port_id).unidir_en       = wb_port_prop.unidir_en;
        DMPS_DB_PORT(wb_port_prop.port_id).rx_rst_hold     = wb_port_prop.rx_rst_hold;
        DMPS_DB_PORT(wb_port_prop.port_id).is_ctle_running = wb_port_prop.is_ctle_running;
        DMPS_DB_PORT(wb_port_prop.port_id).xpipe_en        = wb_port_prop.xpipe_en;
        DMPS_DB_PORT(wb_port_prop.port_id).is_an_first     = wb_port_prop.is_an_first;
        DMPS_DB_PORT(wb_port_prop.port_id).link_fsm        = wb_port_prop.link_fsm;
        DMPS_DB_PORT(wb_port_prop.port_id).link_mode       = wb_port_prop.link_mode;

    CTC_WB_QUERY_ENTRY_END(wb_query);
done:
    return ret;
}

int32
_sys_usw_dmps_mac_wb_restore(uint8 lchip,  ctc_wb_query_t *wb_query)
{
    uint32 entry_cnt = 0;
    int32 ret = CTC_E_NONE;
    sys_wb_dmps_mac_t  p_wb_port_dmps_mac = {0};

    CTC_WB_INIT_QUERY_T(wb_query, sys_wb_dmps_mac_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAC);
    CTC_WB_QUERY_ENTRY_BEGIN(wb_query);

        sal_memcpy((uint8*)&p_wb_port_dmps_mac, (uint8*)(wb_query->buffer) + entry_cnt * (wb_query->key_len + wb_query->data_len), wb_query->key_len + wb_query->data_len);
        entry_cnt++;
        DMPS_DB_MAC(p_wb_port_dmps_mac.mac_id).mac_speed    = p_wb_port_dmps_mac.mac_speed;
        DMPS_DB_MAC(p_wb_port_dmps_mac.mac_id).mac_group_id = p_wb_port_dmps_mac.mac_group_id;
        DMPS_DB_MAC(p_wb_port_dmps_mac.mac_id).mac_idx      = p_wb_port_dmps_mac.mac_idx;
        DMPS_DB_MAC(p_wb_port_dmps_mac.mac_id).en           = p_wb_port_dmps_mac.en;
    CTC_WB_QUERY_ENTRY_END(wb_query);

done:
    return ret;
}

int32
_sys_usw_dmps_pcs_wb_restore(uint8 lchip,  ctc_wb_query_t *wb_query)
{
    uint32 entry_cnt = 0;
    int32 ret = CTC_E_NONE;
    sys_wb_dmps_pcs_t  p_wb_port_dmps_pcs = {0};

    CTC_WB_INIT_QUERY_T(wb_query, sys_wb_dmps_pcs_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PCS);
    CTC_WB_QUERY_ENTRY_BEGIN(wb_query);

        sal_memcpy((uint8*)&p_wb_port_dmps_pcs, (uint8*)(wb_query->buffer) + entry_cnt * (wb_query->key_len + wb_query->data_len), wb_query->key_len + wb_query->data_len);
        entry_cnt++;

        DMPS_DB_PCS(p_wb_port_dmps_pcs.pcs_id).pcs_idx   = p_wb_port_dmps_pcs.pcs_idx;
        DMPS_DB_PCS(p_wb_port_dmps_pcs.pcs_id).rx_rst_en = p_wb_port_dmps_pcs.rx_rst_en;
    CTC_WB_QUERY_ENTRY_END(wb_query);

done:
    return ret;
}

int32
_sys_usw_dmps_chan_wb_restore(uint8 lchip,  ctc_wb_query_t *wb_query)
{
    uint32 entry_cnt = 0;
    int32 ret = CTC_E_NONE;
    sys_wb_dmps_chan_t  p_wb_port_dmps_chan = {0};

    CTC_WB_INIT_QUERY_T(wb_query, sys_wb_dmps_chan_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN);
    CTC_WB_QUERY_ENTRY_BEGIN(wb_query);

        sal_memcpy((uint8*)&p_wb_port_dmps_chan, (uint8*)(wb_query->buffer) + entry_cnt * (wb_query->key_len + wb_query->data_len), wb_query->key_len + wb_query->data_len);
        entry_cnt++;

        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).core_id       = p_wb_port_dmps_chan.core_id;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).pp_id         = p_wb_port_dmps_chan.pp_id;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).dp_id         = p_wb_port_dmps_chan.dp_id;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).txqm_id       = p_wb_port_dmps_chan.txqm_id;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).sub_chan_id   = p_wb_port_dmps_chan.sub_chan_id;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).mac_client_id = p_wb_port_dmps_chan.mac_client_id;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).speed_mode    = p_wb_port_dmps_chan.speed_mode;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).is_rsv        = p_wb_port_dmps_chan.is_rsv;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).prio          = p_wb_port_dmps_chan.prio;
        DMPS_DB_CHAN(p_wb_port_dmps_chan.chan_id).speed_value   = p_wb_port_dmps_chan.speed_value;
    CTC_WB_QUERY_ENTRY_END(wb_query);

done:
    return ret;
}

int32
_sys_usw_dmps_chan_rx_wb_restore(uint8 lchip,  ctc_wb_query_t *wb_query)
{
    uint32 entry_cnt = 0;
    int32 ret = CTC_E_NONE;
    sys_wb_dmps_chan_rx_t  p_wb_port_dmps_chan_rx = {0};

    CTC_WB_INIT_QUERY_T(wb_query, sys_wb_dmps_chan_rx_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN_RX);
    CTC_WB_QUERY_ENTRY_BEGIN(wb_query);

        sal_memcpy((uint8*)&p_wb_port_dmps_chan_rx, (uint8*)(wb_query->buffer) + entry_cnt * (wb_query->key_len + wb_query->data_len), wb_query->key_len + wb_query->data_len);
        entry_cnt++;

        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).core_id       = p_wb_port_dmps_chan_rx.core_id;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).pp_id         = p_wb_port_dmps_chan_rx.pp_id;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).dp_id         = p_wb_port_dmps_chan_rx.dp_id;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).txqm_id       = p_wb_port_dmps_chan_rx.txqm_id;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).sub_chan_id   = p_wb_port_dmps_chan_rx.sub_chan_id;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).mac_client_id = p_wb_port_dmps_chan_rx.mac_client_id;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).speed_mode    = p_wb_port_dmps_chan_rx.speed_mode;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).is_rsv        = p_wb_port_dmps_chan_rx.is_rsv;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).prio          = p_wb_port_dmps_chan_rx.prio;
        DMPS_DB_CHAN_RX(p_wb_port_dmps_chan_rx.chan_id).speed_value   = p_wb_port_dmps_chan_rx.speed_value;
    CTC_WB_QUERY_ENTRY_END(wb_query);

done:
    return ret;
}

int32
_sys_usw_dmps_physical_serdes_wb_restore(uint8 lchip,  ctc_wb_query_t *wb_query)
{
    uint32 entry_cnt = 0;
    int32 ret = CTC_E_NONE;
    sys_wb_dmps_psd_t  p_wb_port_dmps_physical_serdes = {0};

    CTC_WB_INIT_QUERY_T(wb_query, sys_wb_dmps_psd_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD);
    CTC_WB_QUERY_ENTRY_BEGIN(wb_query);

        sal_memcpy((uint8*)&p_wb_port_dmps_physical_serdes, (uint8*)(wb_query->buffer) + entry_cnt * (wb_query->key_len + wb_query->data_len), wb_query->key_len + wb_query->data_len);
        entry_cnt++;

        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).pll_sel          = p_wb_port_dmps_physical_serdes.pll_sel;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).rate_div         = p_wb_port_dmps_physical_serdes.rate_div;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).bit_width        = p_wb_port_dmps_physical_serdes.bit_width;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).rx_polarity      = p_wb_port_dmps_physical_serdes.rx_polarity;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).support_speed    = p_wb_port_dmps_physical_serdes.support_speed;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).tx_polarity      = p_wb_port_dmps_physical_serdes.tx_polarity;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).ocs              = p_wb_port_dmps_physical_serdes.ocs;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).physical_lane_id = p_wb_port_dmps_physical_serdes.physical_lane_id;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).serdes_speed     = p_wb_port_dmps_physical_serdes.serdes_speed;
        DMPS_DB_PSD(p_wb_port_dmps_physical_serdes.serdes_id).is_dyn           = p_wb_port_dmps_physical_serdes.is_dyn;
    CTC_WB_QUERY_ENTRY_END(wb_query);

done:
    return ret;
}

int32
_sys_usw_dmps_logic_serdes_wb_restore(uint8 lchip,  ctc_wb_query_t *wb_query)
{
    uint32 entry_cnt = 0;
    int32 ret = CTC_E_NONE;
    sys_wb_dmps_lsd_t  p_wb_port_dmps_logic_serdes = {0};

    CTC_WB_INIT_QUERY_T(wb_query, sys_wb_dmps_lsd_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_LSD);
    CTC_WB_QUERY_ENTRY_BEGIN(wb_query);

        sal_memcpy((uint8*)&p_wb_port_dmps_logic_serdes, (uint8*)(wb_query->buffer) + entry_cnt * (wb_query->key_len + wb_query->data_len), wb_query->key_len + wb_query->data_len);
        entry_cnt++;

        DMPS_DB_LSD(p_wb_port_dmps_logic_serdes.serdes_id).logical_lane_id = p_wb_port_dmps_logic_serdes.logical_lane_id;
        DMPS_DB_LSD(p_wb_port_dmps_logic_serdes.serdes_id).pcs_l_idx       = p_wb_port_dmps_logic_serdes.pcs_l_idx;
        DMPS_DB_LSD(p_wb_port_dmps_logic_serdes.serdes_id).hss_id          = p_wb_port_dmps_logic_serdes.hss_id;
    CTC_WB_QUERY_ENTRY_END(wb_query);

done:
    return ret;
}


int32
_sys_usw_dmps_map_wb_restore(uint8 lchip,  ctc_wb_query_t *wb_query)
{
    int32 ret = CTC_E_NONE;
    sys_wb_dmps_map_t* p_wb_port_dmps_map;
    uint32 entry_cnt = 0;
    sys_dmps_mapping_set_t* dest_node = NULL;
    
    CTC_WB_INIT_QUERY_T(wb_query, sys_wb_dmps_map_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAP);
    CTC_WB_QUERY_ENTRY_BEGIN(wb_query);
        p_wb_port_dmps_map = (sys_wb_dmps_map_t*)wb_query->buffer + entry_cnt++;/*after reading entry from sqlite, wb_query->buffer is still the first address of the space*/

        dest_node = mem_malloc(MEM_DMPS_MODULE, sizeof(sys_dmps_mapping_set_t));
        if (NULL == dest_node)
        {
            ret = CTC_E_NO_MEMORY;
            goto done;
        }
        sal_memset(dest_node, 0, sizeof(sys_dmps_mapping_set_t));

        dest_node->dport      = p_wb_port_dmps_map->dport_id;
        dest_node->chan_id    = p_wb_port_dmps_map->chan_id;
        dest_node->chan_rx_id = p_wb_port_dmps_map->chan_rx_id;
        dest_node->lsd        = p_wb_port_dmps_map->logic_serdes_id;
        dest_node->psd        = p_wb_port_dmps_map->physical_serdes_id;
        dest_node->mac_id     = p_wb_port_dmps_map->mac_id;
        dest_node->pcs_id     = p_wb_port_dmps_map->pcs_id;

        if (DMPS_INVALID_VALUE_U16 != p_wb_port_dmps_map->dport_id)
        {
            DMPS_DB_PORT(p_wb_port_dmps_map->dport_id).map.id = p_wb_port_dmps_map->dport_id;
            DMPS_DB_PORT(p_wb_port_dmps_map->dport_id).map.node[DMPS_DB_PORT(p_wb_port_dmps_map->dport_id).map.node_num] = (sys_dmps_mapping_set_t*)&(dest_node->head);
            DMPS_DB_PORT(p_wb_port_dmps_map->dport_id).map.node_num ++;
            DMPS_DB_PORT(p_wb_port_dmps_map->dport_id).map.valid = MAPPING_IS_USED;
            /*port opf alloc*/
            (void)sys_usw_dmps_db_assign_port(lchip, p_wb_port_dmps_map->dport_id);
        }
        if (DMPS_INVALID_VALUE_U16 != p_wb_port_dmps_map->chan_id)
        {
            DMPS_DB_CHAN(p_wb_port_dmps_map->chan_id).map.id = p_wb_port_dmps_map->chan_id;
            DMPS_DB_CHAN(p_wb_port_dmps_map->chan_id).map.node[DMPS_DB_CHAN(p_wb_port_dmps_map->chan_id).map.node_num] = (sys_dmps_mapping_set_t*)&(dest_node->head);
            DMPS_DB_CHAN(p_wb_port_dmps_map->chan_id).map.node_num ++;
            DMPS_DB_CHAN(p_wb_port_dmps_map->chan_id).map.valid = MAPPING_IS_USED;
            /*chan opf alloc*/
            (void)sys_usw_dmps_db_assign_chan_by_dir(lchip, p_wb_port_dmps_map->chan_id, CHAN_DIR_TX);
        }
        if (DMPS_INVALID_VALUE_U16 != p_wb_port_dmps_map->chan_rx_id)
        {
            DMPS_DB_CHAN_RX(p_wb_port_dmps_map->chan_rx_id).map.id = p_wb_port_dmps_map->chan_rx_id;
            DMPS_DB_CHAN_RX(p_wb_port_dmps_map->chan_rx_id).map.node[DMPS_DB_CHAN_RX(p_wb_port_dmps_map->chan_rx_id).map.node_num] = (sys_dmps_mapping_set_t*)&(dest_node->head);
            DMPS_DB_CHAN_RX(p_wb_port_dmps_map->chan_rx_id).map.node_num ++;
            DMPS_DB_CHAN_RX(p_wb_port_dmps_map->chan_rx_id).map.valid = MAPPING_IS_USED;
            /*chan opf alloc*/
            (void)sys_usw_dmps_db_assign_chan_by_dir(lchip, p_wb_port_dmps_map->chan_rx_id, CHAN_DIR_RX);
        }
        if (DMPS_INVALID_VALUE_U16 != p_wb_port_dmps_map->logic_serdes_id)
        {
            DMPS_DB_LSD(p_wb_port_dmps_map->logic_serdes_id).map.id = p_wb_port_dmps_map->logic_serdes_id;
            DMPS_DB_LSD(p_wb_port_dmps_map->logic_serdes_id).map.node[DMPS_DB_LSD(p_wb_port_dmps_map->logic_serdes_id).map.node_num] = (sys_dmps_mapping_set_t*)&(dest_node->head);
            DMPS_DB_LSD(p_wb_port_dmps_map->logic_serdes_id).map.node_num ++;
            DMPS_DB_LSD(p_wb_port_dmps_map->logic_serdes_id).map.valid = MAPPING_IS_USED;
        }
        if (DMPS_INVALID_VALUE_U16 != p_wb_port_dmps_map->physical_serdes_id)
        {
            DMPS_DB_PSD(p_wb_port_dmps_map->physical_serdes_id).map.id = p_wb_port_dmps_map->physical_serdes_id;
            DMPS_DB_PSD(p_wb_port_dmps_map->physical_serdes_id).map.node[DMPS_DB_PSD(p_wb_port_dmps_map->physical_serdes_id).map.node_num] = (sys_dmps_mapping_set_t*)&(dest_node->head);
            DMPS_DB_PSD(p_wb_port_dmps_map->physical_serdes_id).map.node_num ++;
            DMPS_DB_PSD(p_wb_port_dmps_map->physical_serdes_id).map.valid = MAPPING_IS_USED;
        }
        if (DMPS_INVALID_VALUE_U16 != p_wb_port_dmps_map->mac_id)
        {
            DMPS_DB_MAC(p_wb_port_dmps_map->mac_id).map.id = p_wb_port_dmps_map->mac_id;
            DMPS_DB_MAC(p_wb_port_dmps_map->mac_id).map.node[DMPS_DB_MAC(p_wb_port_dmps_map->mac_id).map.node_num] = (sys_dmps_mapping_set_t*)&(dest_node->head);
            DMPS_DB_MAC(p_wb_port_dmps_map->mac_id).map.node_num ++;
            DMPS_DB_MAC(p_wb_port_dmps_map->mac_id).map.valid = MAPPING_IS_USED;
        }
        if (DMPS_INVALID_VALUE_U16 != p_wb_port_dmps_map->pcs_id)
        {
            DMPS_DB_PCS(p_wb_port_dmps_map->pcs_id).map.id = p_wb_port_dmps_map->pcs_id;
            DMPS_DB_PCS(p_wb_port_dmps_map->pcs_id).map.node[DMPS_DB_PCS(p_wb_port_dmps_map->pcs_id).map.node_num] = (sys_dmps_mapping_set_t*)&(dest_node->head);
            DMPS_DB_PCS(p_wb_port_dmps_map->pcs_id).map.node_num ++;
            DMPS_DB_PCS(p_wb_port_dmps_map->pcs_id).map.valid = MAPPING_IS_USED;
        }
        ctc_slist_add_tail(&(p_usw_dmps_db_master[lchip]->map_node_list), &(dest_node->head));
    CTC_WB_QUERY_ENTRY_END(wb_query);
done:
    return ret;
}


int32 sys_usw_dmps_wb_restore_master(uint8 lchip)
{
    int32 ret = CTC_E_NONE;
    ctc_wb_query_t    wb_query;

    sys_wb_dmps_master_t* p_wb_dmps_master = NULL;
    uint32 entry_cnt = 0;

    p_wb_dmps_master = (sys_wb_dmps_master_t*)mem_malloc(MEM_DMPS_MODULE, sizeof(sys_wb_dmps_master_t));
    if (NULL == p_wb_dmps_master)
    {
        return CTC_E_NO_MEMORY;
    }

    /*restore port property*/
    CTC_WB_ALLOC_BUFFER(&wb_query.buffer);

    CTC_WB_INIT_QUERY_T((&wb_query),sys_wb_dmps_master_t, CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER);

    /*set default value*/
    sal_memset(p_wb_dmps_master, 0, sizeof(sys_wb_dmps_master_t));
    CTC_ERROR_GOTO(ctc_wb_query_entry(&wb_query), ret, done);
    if (wb_query.valid_cnt != 1 || wb_query.is_end != 1)
    {
        CTC_WB_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "query dmps master error! valid_cnt: %d, is_end: %d.\n", wb_query.valid_cnt, wb_query.is_end);
        ret = CTC_E_NONE;
        goto done;
    }
    sal_memcpy((uint8*)p_wb_dmps_master, (uint8*)(wb_query.buffer) + entry_cnt * (wb_query.key_len + wb_query.data_len), wb_query.key_len + wb_query.data_len);

    sal_memcpy( p_usw_dmps_db_master[lchip]->ext_lport_map,p_wb_dmps_master->ext_lport_map, sizeof(uint16)*DMPS_MAX_PORT_NUM);
    sal_memcpy(p_usw_dmps_db_master[lchip]->cpumac_map, p_wb_dmps_master->cpumac_map, sizeof(sys_dmps_db_cpumac_map_t)*DMPS_MAX_NUM_CPUMAC_MAP);
    sal_memcpy( p_usw_dmps_db_master[lchip]->mac_group_is_valid, p_wb_dmps_master->mac_group_is_valid,sizeof(uint32)*DMPS_MAX_CORE_NUM);
    sal_memcpy( p_usw_dmps_db_master[lchip]->cpumac_dport,p_wb_dmps_master->cpumac_dport, sizeof(uint16)*DMPS_MAX_NUM_CPUMAC_MAP);
    sal_memcpy( p_usw_dmps_db_master[lchip]->chan_2_logic_serdes, p_wb_dmps_master->chan_2_logic_serdes, \
                                                        sizeof(sys_dmps_db_chan2lsd_map_t)*DMPS_MAX_CORE_NUM*DMPS_NW_CPU_NUM_PER_CORE);
	p_usw_dmps_db_master[lchip]->xpipe_alloc = p_wb_dmps_master->xpipe_alloc;

    CTC_ERROR_GOTO(_sys_usw_dmps_port_wb_restore(lchip, &wb_query), ret, done);
    CTC_ERROR_GOTO(_sys_usw_dmps_mac_wb_restore(lchip, &wb_query), ret, done);
    CTC_ERROR_GOTO(_sys_usw_dmps_pcs_wb_restore(lchip, &wb_query), ret, done);
    CTC_ERROR_GOTO(_sys_usw_dmps_chan_wb_restore(lchip, &wb_query), ret, done);
    CTC_ERROR_GOTO(_sys_usw_dmps_chan_rx_wb_restore(lchip, &wb_query), ret, done);
    CTC_ERROR_GOTO(_sys_usw_dmps_physical_serdes_wb_restore(lchip, &wb_query), ret, done);
    CTC_ERROR_GOTO(_sys_usw_dmps_logic_serdes_wb_restore(lchip, &wb_query), ret, done);
    CTC_ERROR_GOTO(_sys_usw_dmps_map_wb_restore(lchip, &wb_query), ret, done);

done:
   CTC_WB_FREE_BUFFER(wb_query.buffer);
   mem_free(p_wb_dmps_master);

   return ret;
}

int32
sys_usw_dmps_wb_init(uint8 lchip)
{
   ctc_wb_appid_t  appid;
   sal_memset(&appid,0,sizeof(appid));

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MASTER) ;
   appid.entry_num = 1;
   appid.entry_size  = sizeof(sys_wb_dmps_master_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PORT) ;
   appid.entry_num =  DMPS_MAX_PORT_NUM;
   appid.entry_size  = sizeof(sys_wb_dmps_port_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAC) ;
   appid.entry_num =  DMPS_MAX_MAC_NUM;
   appid.entry_size  = sizeof(sys_wb_dmps_mac_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN) ;
   appid.entry_num =  DMPS_MAX_CHAN_NUM;
   appid.entry_size  = sizeof(sys_wb_dmps_chan_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_CHAN_RX) ;
   appid.entry_num =  DMPS_MAX_CHAN_NUM;
   appid.entry_size  = sizeof(sys_wb_dmps_chan_rx_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PCS) ;
   appid.entry_num =  DMPS_MAX_PCS_NUM;
   appid.entry_size  = sizeof(sys_wb_dmps_pcs_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_LSD) ;
   appid.entry_num =  DMPS_MAX_SERDES_NUM;
   appid.entry_size  = sizeof(sys_wb_dmps_lsd_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_PSD) ;
   appid.entry_num =  DMPS_MAX_SERDES_NUM;
   appid.entry_size  = sizeof(sys_wb_dmps_psd_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   appid.app_id = lchip << 16 | CTC_WB_APPID(CTC_FEATURE_DATAPATH, SYS_WB_APPID_DMPS_DMPS_SUBID_MAP) ;
   appid.entry_num =  DMPS_MAX_PORT_NUM*2;
   appid.entry_size  = sizeof(sys_wb_dmps_map_t);
   appid.rt_en = 0;
   ctc_wb_add_appid( lchip, &appid);

   return 0;
}

